public class FBComponentBase extends IWBaseComponent {

	public static final String COMPONENT_FAMILY = "formbuilder";

	protected Logger logger = Logger.getLogger(FBComponentBase.class.getName());

	private String id;
	private String styleClass;

	public FBComponentBase() {
		this(null, null);
	}

	public FBComponentBase(String id, String styleClass) {
		super();
		setRendererType(null);
		this.id = id;
		this.styleClass = styleClass;
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public void setId(String id) {
		this.id = id;
	}

	public String getStyleClass() {
		return styleClass;
	}

	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	@Override
	public void renderChild(FacesContext context, UIComponent component) throws IOException {
		if(component.isRendered()) {
			component.encodeBegin(context);
			component.encodeChildren(context);
			component.encodeEnd(context);
		}
	}

	public void addFacet(String name, UIComponent component) {
		getFacets().put(name, component);
	}

	@SuppressWarnings("unchecked")
	public void addChild(UIComponent child, UIComponent parent) {
		parent.getChildren().add(child);
	}

	@Override
	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	@Override
	public boolean getRendersChildren() {
		return true;
	}

	@Override
	public String getRendererType() {
		return null;
	}

	@Override
	public Object saveState(FacesContext context) {
		Object values[] = new Object[3];
		values[0] = super.saveState(context);
		values[1] = id;
		values[2] = styleClass;
		return values;
	}

	@Override
	public void restoreState(FacesContext context, Object state) {
		Object values[] = (Object[]) state;
		super.restoreState(context, values[0]);
		id = (String) values[1];
		styleClass = (String) values[2];
	}

	protected static String _(String localizationKey) {
		return WFUtil.getLocalizedStringExpr(IWBundleStarter.IW_BUNDLE_IDENTIFIER, localizationKey);
	}

	protected static String _(IWContext iwc, String localizationKey, String defaultString) {
		IWMainApplication iwma = iwc.getApplicationContext().getIWMainApplication();
		IWBundle bundle = iwma.getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER);
		return bundle.getResourceBundle(iwc.getCurrentLocale()).getLocalizedString(localizationKey, defaultString);
	}

	public static String getLocalizedString(IWContext iwc, String localizationKey, String defaultString) {
		IWMainApplication iwma = iwc.getApplicationContext().getIWMainApplication();
		IWBundle bundle = iwma.getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER);
		return bundle.getResourceBundle(iwc.getCurrentLocale()).getLocalizedString(localizationKey, defaultString);
	}

	@Override
	public void encodeChildren(FacesContext context) throws IOException {
		for(Iterator<UIComponent> it = getChildren().iterator(); it.hasNext(); ) {
			RenderUtils.renderChild(context, it.next());
		}
	}
} public class ComponentPropertyManager {

	private static final String BUTTON_LABEL_PROP = "buttonLabel";
	private static final String COMP_LABEL_PROP = "compLabel";
//	private static final String COMP_ERROR_PROP = "compError";
	private static final String COMP_HELP_PROP = "compHelp";
	private static final String COMP_REQ_PROP = "compRequired";
	private static final String COMP_CALCULATE_PROP = "compCalculate";
//	private static final String COMP_VALIDATATION_PROP = "compValidation";
	private static final String PLAIN_LABEL_PROP = "plainLabel";
	private static final String PLAIN_TEXT_PROP = "plainText";
	private static final String COMP_AUTO_PROP = "compAuto";
	private static final String COMP_ADD_BUTTON_PROP = "compAddButton";
	private static final String COMP_REMOVE_BUTTON_PROP = "compRemoveButton";
	private static final String COMP_EXT_SRC_PROP = "externalSrc";
	private static final String COMP_UPL_DESC_PROP = "uploadDesc";
	private static final String COMP_UPL_DESC_LBL_PROP = "uploadDescLbl";
	private static final String COMP_UPL_HEADER_TEXT_PROP = "uploadHeaderText";
	public static final String COMP_USE_HTML_EDITOR = "compUseHtmlEditor";
	
	public static final String BEAN_ID = "propertyManager";

	private GenericComponent component;

	private FormPage formPage;

	public FormPage getFormPage() {
		return formPage;
	}
	
	public void resetComponent() {
		component = null;
	}
	
	public boolean resetComponent(Component comp) {
		if(component != null && comp != null) {
			if(component.getId().equals(comp.getId())) {
				component = null;
				
				return true;
			}
		}
		
		return false;
	}

	public String getSelectedComponentId() {
		if (component != null) {
			return component.getComponent().getId();
		} else {
			return CoreConstants.EMPTY;
		}
	}

	public void setFormPage(FormPage formPage) {
		this.formPage = formPage;
	}

	public GenericComponent getComponent() {
		return component;
	}

	public void setComponent(GenericComponent component) {
		this.component = component;
	}

	public Object[] switchDataSource() {
		if (component.getDataSrc().equals(DataSourceList.externalDataSrc)) {
			component.setDataSrc(DataSourceList.localDataSrc);
			List<ItemBean> itemSet = component.getItems();
			itemSet.clear();
			component.setItems(itemSet);
		} else {
			component.setDataSrc(DataSourceList.externalDataSrc);
			List<ItemBean> itemSet = component.getItems();
			itemSet.clear();
			component.setItems(itemSet);
		}
		Object[] result = { component.getComponent().getId(), getFormComponent(component), getPropertiesPanel(component) };
		return result;
	}
	
	public Object[] selectComponent(String id, String type) {
		if (type == null || id == null) {
			return null;
		}

		Object[] values = new Object[2];
		
		values[1] = component == null ? null : component.getId();
		
		Page page = formPage.getPage();
		if (page != null) {
			if (type.equals(FormComponent.COMPONENT_TYPE)) {
				Component comp = page.getComponent(id);
				if (comp instanceof ComponentMultiUpload) {
					component = new FormMultiUploadComponent((ComponentMultiUpload) comp);
				} else if (comp instanceof ComponentStatic) {
					component = new FormPlainComponent((ComponentStatic) comp);
				} else if (comp instanceof ComponentSelect) {
					component = new FormSelectComponent((ComponentSelect) comp);
				} else {
					component = new FormComponent(comp);
				}
			} else if (type.equals(FormComponent.BUTTON_TYPE)) {
				ButtonArea area = page.getButtonArea();
				if (area != null) {
					Button button = (Button) area.getComponent(id);
					component = new FormButton(button);
				}
			}
			values[0] = getPropertiesPanel(component);
		}
		
		return values;
	}

	public Document saveAutofill(boolean autofill) {
		if (autofill) {
			component.setAutofillKey("example");
		} else {
			component.setAutofillKey(CoreConstants.EMPTY);
		}
		return getPropertiesPanel(component);
	}

	public Object[] removeSelectOption(int index) {
		removeItem(index);
		Object[] result = { component.getComponent().getId(), getFormComponent(component) };
		return result;
	}

	public void removeItem(int index) {
		List<ItemBean> itemSet = component.getItems();
		if (index < itemSet.size()) {
			itemSet.remove(index);
		}
		component.setItems(itemSet);
	}

	public Object[] saveSelectOptionLabel(int index, String value) {
		int size = component.getItems().size();
		List<ItemBean> itemSet = component.getItems();
		if (index >= size) {
			ItemBean newItem = new ItemBean();
			newItem.setLabel(value);
			newItem.setValue(value);
			itemSet.add(newItem);
		} else {
			itemSet.get(index).setLabel(value);
			itemSet.get(index).setValue(value);
		}
		component.setItems(itemSet);
		Object[] result = { component.getComponent().getId(), getFormComponent(component) };
		return result;
	}

	public Object[] saveSelectOptionValue(int index, String value) {
		List<ItemBean> itemSet = component.getItems();
		if (index >= itemSet.size()) {
			ItemBean newItem = new ItemBean();
			newItem.setValue(value);
			itemSet.add(newItem);
		} else {
			itemSet.get(index).setValue(value);
		}
		component.setItems(itemSet);
		Object[] result = { component.getComponent().getId(), getFormComponent(component) };
		return result;
	}

	public Object[] saveComponentErrorMessage(String errorTypeStr, String errorMessage) {

		ErrorType errType = ErrorType.getByStringRepresentation(errorTypeStr);

		if (errType != null) {
			component.setErrorMessage(errType, errorMessage);
		} else {
			Logger.getLogger(getClass().getName()).log(Level.WARNING,"Tried to set error message, but no error type resolved by error type string provided="+ errorTypeStr);
		}

		return getResponse(component, false);
	}
	
	public Object[] saveComponentCalcExpression(String calcExp) {
		
		component.setCalculate(calcExp);

		return getResponse(component, false);
	}


	// TODO: remove componentId param
	public Object[] saveComponentProperty(String componentId, String propertyName, String propertyValue) {
		if (propertyName == null || propertyValue == null || component == null) {
			Logger.getLogger(getClass().getName()).log(Level.WARNING, "Tried to save component property, but either property name or value not set. PropertyName=" + propertyName + ", propertyValue=" + propertyValue);
			return null;
		}
		
		boolean reloadProperties = false;
		
		if(componentId == null || !componentId.equals(component.getId())) {
			return null;
		}

		if (propertyName.equals(BUTTON_LABEL_PROP)) {
			component.setLabel(propertyValue);
			Object[] result = { component.getId(), propertyValue };
			return result;
		} else {
			if (propertyName.equals(COMP_LABEL_PROP)) {
				component.setLabel(propertyValue);
			} else if (propertyName.equals(COMP_HELP_PROP)) {
				component.setHelpMessage(propertyValue);
			} else if (propertyName.equals(COMP_REQ_PROP)) {
				component.setRequired(Boolean.parseBoolean(propertyValue));
				reloadProperties = true;
			} else if (propertyName.equals(COMP_CALCULATE_PROP)) {
				component.setIsCalculate(Boolean.parseBoolean(propertyValue));
				component.setCalculate(component.getCalculate());
				reloadProperties = true;
			} else if (propertyName.equals(COMP_USE_HTML_EDITOR)) {
				component.setUseHtmlEditor(Boolean.valueOf(propertyValue));
			} else if (propertyName.equals(PLAIN_TEXT_PROP)) {
				component.setPlainText(propertyValue);
			} else if (propertyName.equals(PLAIN_LABEL_PROP)) {
				component.setLabel(propertyValue);
			} else if (propertyName.equals(COMP_ADD_BUTTON_PROP)) {
				component.setAddButtonLabel(propertyValue);
			} else if (propertyName.equals(COMP_AUTO_PROP)) {
				component.setAutofillKey(propertyValue);
			} else if (propertyName.equals(COMP_REMOVE_BUTTON_PROP)) {
				component.setRemoveButtonLabel(propertyValue);
			} else if (propertyName.equals(COMP_EXT_SRC_PROP)) {
				if (CoreConstants.EMPTY.equals(propertyValue)) {
					propertyValue = null;
				}
				component.setExternalSrc(propertyValue);
			} else if (propertyName.equals(COMP_UPL_DESC_PROP)) {
				component.setUploadDescription(propertyValue);
			} else if (propertyName.equals(COMP_UPL_DESC_LBL_PROP)) {
				component.setDescriptionLabel(propertyValue);
			} else if (propertyName.equals(COMP_UPL_HEADER_TEXT_PROP)) {
				component.setUploaderHeaderText(propertyValue);
			}
			
			return getResponse(component, reloadProperties);
		}
	}

	private Object[] getResponse(GenericComponent component, boolean reloadProperties) {
		Document propertiesPanel = null;
		if(reloadProperties) {
			propertiesPanel = getPropertiesPanel(component);
		}
		return new Object[] { component.getId(), getFormComponent(component), propertiesPanel };
	}
	
	private Document getPropertiesPanel(GenericComponent component) {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBComponentProperties(component),true);
	}
	
	private Document getFormComponent(GenericComponent component) {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(),new FBFormComponent(component.getComponent()), true);
	}
} public class DataSourceList implements Serializable {

	private static final long serialVersionUID = -1462694112346788168L;
	private static final String select_sources = "select-external_data_sources";
	private static final Logger logger = Logger.getLogger(DataSourceList.class.getName());

	public static String localDataSrc = new Integer(PropertiesSelect.LOCAL_DATA_SRC).toString();
	public static String externalDataSrc = new Integer(PropertiesSelect.EXTERNAL_DATA_SRC).toString();

	private List<SelectItem> sources = new ArrayList<SelectItem>();
	private List<SelectOption> extDataSources;

	public DataSourceList() {
		sources.clear();
		sources.add(new SelectItem(localDataSrc, "List of values"));
		sources.add(new SelectItem(externalDataSrc, "External"));
	}

	public List<SelectItem> getSources() {
		return sources;
	}

	public void setSources(List<SelectItem> sources) {
		this.sources = sources;
	}

	public List<SelectOption> getExternalDataSources() {

		if(extDataSources == null) {

			extDataSources = new ArrayList<SelectOption>();
			extDataSources.add(new SelectOption("Choose", ""));

			try {
				Map<String, String> localizedStrings = (BundleLocalizationMap) ((HashMap<?, ?>) WFUtil.getBeanInstance("localizedStrings")).get(IWBundleStarter.IW_BUNDLE_IDENTIFIER);

				Config cfg = ConfigFactory.getInstance().getConfig(IWBundleStarter.IW_BUNDLE_IDENTIFIER, IWBundleStarter.FB_CFG_FILE);
				Map<String, String > properties = cfg.getProperies(select_sources);

				if(properties != null) {

					for (String srcKey : properties.keySet())
						extDataSources.add(new SelectOption(localizedStrings.get(srcKey+".label"), properties.get(srcKey)));
				}


			} catch (ConfigException e) {
				logger.log(Level.SEVERE, "Unable to load select external data sources list. Config key provided: "+select_sources, e);
			}
		}

		return extDataSources;
	}
} public class FormButton extends GenericComponent {
	
	public static final String BEAN_ID = "formButton";
	
	private Button button;
	
	@Override
	public Component getComponent() {
		return button;
	}
	
	@Override
	public void setLabel(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getLabel();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setLabel(bean);
	}
	
	@Override
	public String getId() {
		return button.getId();
	}
	
	@Override
	public List<ItemBean> getItems() {return null;}
	
	@Override
	public void setItems(List<ItemBean> list) {}
	
	@Override
	public void setExternalSrc(String externalSrc) {}
	
	@Override
	public void setErrorMessage(ErrorType errorType, String value) {}
	
	@Override
	public String getErrorMessage(ErrorType errorType) {return null;}
	
	@Override
	public void setHelpMessage(String value) {}
	
	@Override
	public String getHelpMessage() {return null;}
	
	public void setValidationText(String value) {}
	
	public String getValidationText() {return null;}
	
	@Override
	public void setPlainText(String value) {}
	
	@Override
	public String getPlainText() {return null;}

	public String getCompText() {return null;}
	
	public void setCompText(String value) { }
	
	@Override
	public void setAddButtonLabel(String value) {}
	
	@Override
	public void setRemoveButtonLabel(String value) {}
	
	@Override
	public void setRequired(boolean value) {}
	
	@Override
	public boolean getRequired() {return false;}
	
	@Override
	public String getExternalSrc() {return null;}
	
	@Override
	public String getRemoveButtonLabel() {return null;}
	
	@Override
	public String getAddButtonLabel() {return null;}
	
	@Override
	public String getDataSrc() {return null;}

	@Override
	public void setDataSrc(String dataSrc) {}
	
	@Override
	public String getAutofillKey() {return null;}

	@Override
	public void setAutofillKey(String autofillKey) {}
	
	@Override
	public String getUploadDescription() {return null;}
	
	@Override
	public void setUploadDescription(String value) {}
	
	@Override
	public void setUploaderHeaderText(String value) {}
	
	@Override
	public String getUploadHeaderText() {return null;}

	private FormPage formPage;
	
	public FormPage getFormPage() {
		return formPage;
	}

	public void setFormPage(FormPage formPage) {
		this.formPage = formPage;
	}
	
	public FormButton() {}
	
	public FormButton(Button button) {
		this.button = button;
	}
	
	public Button getButton() {
		return button;
	}
	public void setButton(Button button) {
		this.button = button;
	}
	
	@Override
	public String getLabel() {
		if(button == null)
			return null;
		LocalizedStringBean bean = button.getProperties().getLabel();
		if(bean != null) {
			return bean.getString(FBUtil.getUILocale());
		} else {
			return null;
		}
	}
	
	public Document addButton(String type) {
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			Button button = null;
			if(area != null) {
				button = area.addButton(ConstButtonType.getByStringType(type), null);
			} else {
				area = page.createButtonArea(null);
				button = area.addButton(ConstButtonType.getByStringType(type), null);
			}
			return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBButton(button.getId(), "formButton", "loadButtonInfo(this);", "removeButton(this);"), true);
		}
		return null;
	}
	
	public String removeButton(String id) {
		if(id == null) {
			return null;
		}
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			if(area != null) {
				Button button = (Button) area.getComponent(id);
				if(button != null) {
					button.remove();
					return id;
				}
			}
		}
		return null;
	}

	@Override
    public String getCalculate() {
	    // TODO Auto-generated method stub
	    return null;
    }

	@Override
    public void setCalculate(String expression) {
	    // TODO Auto-generated method stub
	    
    }
	
	@Override
	public void setIsCalculate(boolean value) {}

	@Override
	public boolean isUseHtmlEditor() {
		return false;
	}

	@Override
	public void setUseHtmlEditor(boolean useHtmlEditor) {
	}
	
} public class FormComponent extends GenericComponent {
	
	public static final String BEAN_ID = "formComponent";
	
	public static final String BUTTON_TYPE = "button";
	public static final String COMPONENT_TYPE = "component";
	
	private static final String APPEND = "append";
	
	protected Component component;
	
	private ProcessPalette processPalette;
	private ProcessData processData;
	private FormPage formPage;
	private ComponentPropertyManager propertyManager;
	
	public FormComponent() {}
	
	public FormComponent(Component component) {
		this.component = component;
	}
	
	public ComponentPropertyManager getPropertyManager() {
		return propertyManager;
	}

	public void setPropertyManager(ComponentPropertyManager propertyManager) {
		this.propertyManager = propertyManager;
	}

	public FormPage getFormPage() {
		return formPage;
	}
	
	@Override
	public String getId() {
		return component.getId();
	}

	public void setFormPage(FormPage formPage) {
		this.formPage = formPage;
	}
	
	public String[] assignVariable(String componentId, String variable) {
		if(componentId == null) {
			componentId = component.getId();
		}
		Page page = formPage.getPage();
		if(page != null) {
			Component component = page.getComponent(componentId);
			PropertiesComponent properties = component.getProperties();
			if(properties != null) {
				Variable oldVar = properties.getVariable();
				String oldVarName = null;
				if(oldVar != null) {
					oldVarName = oldVar.getDefaultStringRepresentation();
					processData.unbindVariable(oldVarName, componentId);
				}
				properties.setVariable(variable);
				
				String[] result = new String[3];
				result[0] = processData.bindVariable(componentId, variable).getStatus();
				result[1] = oldVarName;
				result[2] = oldVarName == null ? null : processData.getVariableStatus(oldVarName).getStatus();
				
				return result;
			}
		}
		return null;
	}
	
	public String[] removeVariableBinding(String componentId) {
		if(componentId == null) {
			return null;
		}
		
		Page page = formPage.getPage();
		if(page != null) {
			Component component = page.getComponent(componentId);
			PropertiesComponent properties = component.getProperties();
			if(properties != null) {
				Variable oldVar = properties.getVariable();
				String oldVarName = null;
				if(oldVar != null) {
					oldVarName = oldVar.getDefaultStringRepresentation();
					processData.unbindVariable(oldVarName, componentId);
				}
				properties.setVariable(CoreConstants.EMPTY);
				
				String[] result = new String[2];
				result[0] = oldVarName;
				result[1] = oldVarName == null ? null : processData.getVariableStatus(oldVarName).getStatus();
				
				return result;
			}
		}
		
		return null;
	}
	
	public String[] removeTransitionBinding(String buttonId) {
		if(buttonId == null) {
			return null;
		}
		
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			if(area != null) {
				Button button = (Button) area.getComponent(buttonId);
				PropertiesButton properties = button.getProperties();
				if(properties != null) {
					String action = properties.getReferAction();
					properties.setReferAction(null);
					
					processData.unbindTransition(buttonId, action).getStatus();
					
					String[] result = new String[2];
					result[0] = action;
					result[1] = action == null ? null : processData.getTransitionStatus(action).getStatus();
					
					return result;
				}
			}
		}
		
		return null;
	}
	
	public String[] assignTransition(String buttonId, String transition) {
		if(StringUtils.isEmpty(buttonId) || buttonId.equals("-1")) {
			return null;
		}
		
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			if(area != null) {
				Button button = (Button) area.getComponent(buttonId);
				PropertiesButton properties = button.getProperties();
				if(properties != null) {
					String action = properties.getReferAction();
					properties.setReferAction(transition);
					
					String[] result = new String[4];
					result[0] = processData.bindTransition(buttonId, transition).getStatus();
					result[1] = action;
					result[2] = action == null ? null : processData.getTransitionStatus(action).getStatus();
					
					return result;
				}
			}
		}
		
		return null;
	}
	
	@Override
	public String getDataSrc() {return null;}

	@Override
	public void setDataSrc(String dataSrc) {}
	
	public Document getAvailableProcessDataList(String type, boolean transition) {		
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBVariableList(type, transition), true);
	}
	
	public Object[] addButton(String type, String before, String transition) {
		if(type == null) {
			return null;
		}
		
		Object[] result = new Object[3];
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			
			if(area == null) {
				area = page.createButtonArea(null);
			}
			
			String beforeId = null;
			if(StringUtils.isEmpty(before)) {
				result[0] = APPEND;
			} else {
				List<String> ids = area.getContainedComponentsIds();
				int beforeInt = ids.indexOf(before);
				if(ids.size() > beforeInt + 1) {
					beforeId = ids.get(beforeInt + 1);
				}
			}
			
			Button button = area.addButton(ConstButtonType.getByStringType(type), beforeId);
			Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);
			if(workspace.isProcessMode() && !StringUtils.isEmpty(transition)) {
				PropertiesButton properties = button.getProperties();
				if(properties != null) {
					properties.setReferAction(transition);
					
					result[2] = processData.bindTransition(button.getId(), transition).getStatus();
				}
			}
			
			if(result[0] == null) {
				result[0] = beforeId;
			}
			result[1] = getButton(button);
		}
		return result;
	}
	
	public Object[] addComponent(String type, String before, String variable) throws Exception {
		if(type == null) {
			return null;
		}
		
		Object[] result = new Object[4];
		
		Page page = formPage.getPage();
		if(page.isSpecialPage()) {
			return null;
		}
		if(page != null) {
			String beforeId = null;
			if(StringUtils.isEmpty(before)) {
				result[0] = APPEND;
				
				ButtonArea area = page.getButtonArea();
				if(area != null) {
					beforeId = area.getId();
				}
			} else {
				List<String> ids = page.getContainedComponentsIds();
				int beforeInt = ids.indexOf(before);
				if(ids.size() > beforeInt + 1) {
					beforeId = page.getContainedComponentsIds().get(beforeInt + 1);
					
					ButtonArea area = page.getButtonArea();
					if(area != null && beforeId.equals(area.getId())) {
						result[0] = APPEND;
					}
				}
			}
			Component component = page.addComponent(type, beforeId);
			Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);
			if(workspace.isProcessMode() && !StringUtils.isEmpty(variable)) {
				PropertiesComponent properties = component.getProperties();
				if(properties != null) {
					properties.setVariable(variable);
					
					result[2] = processData.bindVariable(component.getId(), variable).getStatus();
				}
			}
			if(result[0] == null) {
				result[0] = beforeId;
			}
			result[1] = BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBFormComponent(component), true);
			result[3] = component.getId();
		}
		return result;
	}
	
	public String moveComponent(String id, int before) throws Exception {
		if(before == -1) {
			return APPEND;
		} else {
			Page page = formPage.getPage();
			String beforeId = CoreConstants.EMPTY;
			if(page != null) {
				List<String> ids = page.getContainedComponentsIds();
				if(ids.indexOf(id) != -1) {
					beforeId = ids.get(before);
					ids.remove(id);
					ids.add(before, id);
				}
				page.rearrangeComponents();
			}
			return beforeId;
		}
	}
	
	private Document getButtonArea(String styleClass, String componentStyleClass) {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBButtonArea(styleClass, componentStyleClass), true);
	}
	
	private Document getButton(Button button) {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBButton(button.getId(), "formButton", "loadButtonInfo(this);", "removeButton(this);"), true);
	}
	
	private Document getPropertiesPanel(GenericComponent component) {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBComponentProperties(component),true);
	}
	
	private Document getDesignView() {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBDesignView("formElement"), false);
	}
	
	public Object[] removeComponent(String id) {
		if(StringUtils.isEmpty(id)) {
			return null;
		}
		
		Page page = formPage.getPage();
		if(page != null) {
			Component component = page.getComponent(id);
			if(component != null) {
				boolean update = propertyManager.resetComponent(component);
				
				component.remove();
				
				Object[] result = new Object[5];
				result[0] = id;
				result[1] = update ? getPropertiesPanel(null) : null;
				result[2] = formPage.hasRegularComponents() ? null : getDesignView();
				
				Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);
				if(workspace.isProcessMode()) {
					PropertiesComponent properties = component.getProperties();
					if(properties != null) {
						Variable oldVar = properties.getVariable();
						String oldVarName = null;
						if(oldVar != null) {
							oldVarName = oldVar.getDefaultStringRepresentation();
							processData.unbindVariable(oldVarName, id);
						}
						
						result[3] = oldVarName;
						result[4] = oldVarName == null ? null : processData.getVariableStatus(oldVarName).getStatus();
						
					}
				}
				
				return result;
			}
		}
		return null;
	}
	
	public Object[] removeButton(String id) {
		if(StringUtils.isEmpty(id)) {
			return null;
		}
		
		Page page = formPage.getPage();
		if(page != null) {
			ButtonArea area = page.getButtonArea();
			if(area != null) {
				Button button = (Button) area.getComponent(id);
				if(button != null) {
					boolean update = propertyManager.resetComponent(button);
					
					Object[] result = new Object[5];
					result[0] = id;
					
					Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);
					if(workspace.isProcessMode()) {
						PropertiesButton properties = button.getProperties();
						if(properties != null) {
							String action = properties.getReferAction();
							if(action != null) {
								processData.unbindTransition(id, action).getStatus();
							}
							
							result[3] = action;
							result[4] = action == null ? null : processData.getTransitionStatus(action).getStatus();
						}
					}
					
					button.remove();
					
					result[1] = update ? getPropertiesPanel(null) : null;
					result[2] = area.getContainedComponentsIds().isEmpty() ? getButtonArea("formElement formElementHover", "formButton") : null;
					
					return result;
				}
			}
		}
		return null;
	}

	@Override
	public String getErrorMessage(ErrorType errorType) {
		return getComponent().getProperties().getErrorMsg(errorType).getString(FBUtil.getUILocale());
	}

	@Override
	public void setErrorMessage(ErrorType errorType, String errorMessage) {
		LocalizedStringBean bean = getComponent().getProperties().getErrorMsg(errorType);
		bean.setString(FBUtil.getUILocale(), errorMessage);
		getComponent().getProperties().setErrorMsg(errorType, bean);
	}

	@Override
	public String getLabel() {
		return getComponent().getProperties().getLabel().getString(FBUtil.getUILocale());
	}

	@Override
	public void setLabel(String label) {
		LocalizedStringBean bean = getComponent().getProperties().getLabel();
		if(bean == null) {
			bean = new LocalizedStringBean();
		}
		bean.setString(FBUtil.getUILocale(), label);
		getComponent().getProperties().setLabel(bean);
	}
	
	@Override
	public boolean getRequired() {
		return getComponent().getProperties().isRequired();
	}

	@Override
	public void setRequired(boolean required) {
		getComponent().getProperties().setRequired(required);
	}

	@Override
	public List<ItemBean> getItems() {return null;}

	@Override
	public void setItems(List<ItemBean> items) {}

	@Override
	public Component getComponent() {
		return component;
	}

	public void setComponent(Component component) {
		this.component = component;
	}

	@Override
	public String getHelpMessage() {
		return getComponent().getProperties().getHelpText().getString(FBUtil.getUILocale());
	}
	
	@Override
	public void setHelpMessage(String helpMessage) {
		LocalizedStringBean bean = getComponent().getProperties().getHelpText();
		bean.setString(FBUtil.getUILocale(), helpMessage);
		getComponent().getProperties().setHelpText(bean);
	}

	@Override
	public String getAutofillKey() {
		return getComponent().getProperties().getAutofillKey();
	}

	@Override
	public void setAutofillKey(String autofillKey) {
		if(StringUtils.isEmpty(autofillKey)) {
			return;
		}
		getComponent().getProperties().setAutofillKey(autofillKey);
	}

	@Override
	public String getPlainText() {return null;}

	@Override
	public void setPlainText(String plainText) {}
	
	@Override
	public void setAddButtonLabel(String value) {}
	
	@Override
	public void setRemoveButtonLabel(String value) {}
	
	@Override
	public void setExternalSrc(String externalSrc) {}
	
	@Override
	public String getExternalSrc() {return null;}
	
	@Override
	public String getRemoveButtonLabel() {return null;}
	
	@Override
	public String getAddButtonLabel() {return null;}
	
	@Override
	public String getUploadDescription() {return null;}
	
	@Override
	public void setUploadDescription(String value) {}
	
	@Override
	public void setUploaderHeaderText(String value) {}
	
	@Override
	public String getUploadHeaderText() {return null;}


	public ProcessPalette getProcessPalette() {
		return processPalette;
	}

	public void setProcessPalette(ProcessPalette processPalette) {
		this.processPalette = processPalette;
	}

	public ProcessData getProcessData() {
		return processData;
	}

	public void setProcessData(ProcessData processData) {
		this.processData = processData;
	}

	@Override
    public String getCalculate() {
		return getComponent().getProperties().getCalculateExp();

    }

	@Override
    public void setCalculate(String expression) {
		if(StringUtils.isEmpty(expression)) {
			return;
		}
		getComponent().getProperties().setCalculate(expression);
	    
    }

	@Override
	public void setIsCalculate(boolean calculate) {
		getComponent().getProperties().setIsCalculate(calculate);
	}

	@Override
	public boolean isUseHtmlEditor() {
		return getComponent().getProperties().isUseHtmlEditor();
	}

	@Override
	public void setUseHtmlEditor(boolean useHtmlEditor) {
		getComponent().getProperties().setUseHtmlEditor(useHtmlEditor);
	}
} public class FormMultiUploadComponent extends FormComponent {
	
	public FormMultiUploadComponent(ComponentMultiUpload component) {
		this.component = component;
	}

	public ComponentMultiUpload getComponent() {
		return (ComponentMultiUpload) component;
	}

	public void setComponent(ComponentMultiUpload component) {
		this.component = component;
	}
	
	public void setAddButtonLabel(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getInsertButtonLabel();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setInsertButtonLabel(bean);
	}
	
	public void setRemoveButtonLabel(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getRemoveButtonLabel();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setRemoveButtonLabel(bean);
	}
	
	public String getAddButtonLabel() {
		return getComponent().getProperties().getInsertButtonLabel().getString(FBUtil.getUILocale());
	}
	
	public String getRemoveButtonLabel() {
		return getComponent().getProperties().getRemoveButtonLabel().getString(FBUtil.getUILocale());
	}
	
	public String getUploadDescription() {
		return getComponent().getProperties().getUploadingFileDescription().getString(FBUtil.getUILocale());
	}
	
	public String getDescriptionLabel() {
		return getComponent().getProperties().getDescriptionLabel().getString(FBUtil.getUILocale());
	}
	
	public String getUploaderHeaderText() {
		return getComponent().getProperties().getUploaderHeaderText().getString(FBUtil.getUILocale());
	}
	
	public void setUploadDescription(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getUploadingFileDescription();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setUploadingFileDescription(bean);
	}
	
	public void setDescriptionLabel(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getUploadingFileDescription();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setDescriptionLabel(bean);
	}
	
	public void setUploaderHeaderText(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getUploaderHeaderText();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setUploaderHeaderText(bean);
	}
} public class FormPlainComponent extends FormComponent {
	
	public FormPlainComponent(ComponentStatic component) {
		this.component = component;
	}
	
	public ComponentStatic getComponent() {
		return (ComponentStatic) component;
	}
	
	public void setPlainText(String value) {
		LocalizedStringBean bean = getComponent().getProperties().getText();
		bean.setString(FBUtil.getUILocale(), value);
		getComponent().getProperties().setText(bean);
	}
	
	public String getPlainText() {
		return getComponent().getProperties().getText() == null ? null : getComponent().getProperties().getText().getString(FBUtil.getUILocale());
	}

} public class FormSelectComponent extends FormComponent {
	
	public FormSelectComponent(ComponentSelect component) {
		this.component = component;
	}

	@Override
	public ComponentSelect getComponent() {
		return (ComponentSelect) component;
	}

	public void setComponent(ComponentSelect component) {
		this.component = component;
	}
	
	@Override
	public void setExternalSrc(String externalSrc) {
		getComponent().getProperties().setExternalDataSrc(externalSrc);
	}
	
	@Override
	public String getExternalSrc() {
		return getComponent().getProperties().getExternalDataSrc();
	}
	
	@Override
	public List<ItemBean> getItems() {
		if(getComponent() != null && getComponent().getProperties() != null && getComponent().getProperties().getItemset() != null) {
			Logger.getLogger(getClass().getName()).info("items="+getComponent().getProperties().getItemset());
			return getComponent().getProperties().getItemset().getItems(FBUtil.getUILocale());
		}
		return new ArrayList<ItemBean>();
	}
	
	@Override
	public void setItems(List<ItemBean> items) {
		getComponent().getProperties().getItemset().setItems(FBUtil.getUILocale(), items);
	}
	
	@Override
	public String getDataSrc() {
		if(getComponent().getProperties().getDataSrcUsed() != null) {
			return getComponent().getProperties().getDataSrcUsed().toString();
		} else {
			return DataSourceList.localDataSrc;
		}
	}

	@Override
	public void setDataSrc(String dataSrc) {
		getComponent().getProperties().setDataSrcUsed(Integer.parseInt(dataSrc));
	}

} public abstract class GenericComponent {

	public abstract String getId();

	public abstract Component getComponent();

	public abstract void setLabel(String value);

	public abstract String getLabel();

	public abstract void setErrorMessage(ErrorType errorType, String value);

	public abstract String getErrorMessage(ErrorType errorType);

	public abstract void setHelpMessage(String value);

	public abstract String getHelpMessage();

//	public abstract void setValidationText(String value);
//
//	public abstract String getValidationText();

	public abstract void setRequired(boolean value);

	public abstract boolean getRequired();

	public abstract void setPlainText(String value);

	public abstract String getPlainText();

	public abstract void setAddButtonLabel(String value);

	public abstract String getAddButtonLabel();

	public abstract void setRemoveButtonLabel(String value);

	public abstract String getRemoveButtonLabel();
	
	public String getDescriptionLabel() {
		return null;
	}

	public void setDescriptionLabel(String value) {
	}

	public abstract void setExternalSrc(String value);

	public abstract String getExternalSrc();

	public abstract List<ItemBean> getItems();

	public abstract void setItems(List<ItemBean> list);

	public abstract String getDataSrc();

	public abstract void setDataSrc(String dataSrc);

	public abstract void setAutofillKey(String key);

	public abstract String getAutofillKey();

	public abstract String getUploadDescription();

	public abstract void setUploadDescription(String value);
	
	public abstract String getUploadHeaderText();

	public abstract void setUploaderHeaderText(String value);
	
	public abstract void setCalculate(String expression);

	public abstract String getCalculate();

	public abstract void setIsCalculate(boolean isCalculate);

	public abstract void setUseHtmlEditor(boolean useHtmlEditor);
	
	public abstract boolean isUseHtmlEditor();
} public class Workspace implements Serializable {

	private static final long serialVersionUID = -7539955904708793992L;

	public static final String BEAN_ID = "workspace";

	private String view;
	private Long parentFormId;
	private Long processId;
	private String taskName;
	private Locale locale;
	private boolean processMode;
	private String activeHomepageTab;

	@Autowired
	private Web2Business web2;

	@Autowired
	private JQuery jQuery;

	public String getActiveHomepageTab() {
		return activeHomepageTab;
	}

	public void setActiveHomepageTab(String activeHomepageTab) {
		this.activeHomepageTab = activeHomepageTab;
	}

	public boolean isProcessMode() {
		return processMode;
	}

	public void setProcessMode(boolean processMode) {
		this.processMode = processMode;
	}

	public Locale getLocale() {
		if(locale == null) {
			locale = IWContext.getInstance().getCurrentLocale();
		}
		return locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	public Workspace() {
		this.view = FBViewPanel.DESIGN_VIEW;
		this.locale = IWContext.getInstance().getCurrentLocale();
		this.processMode = false;
	}

	public String redirectHome() {
		return "redirectHome";
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	public Long getParentFormId() {
		return parentFormId;
	}

	public void setParentFormId(Long parentFormId) {
		this.parentFormId = parentFormId;
	}

	public Long getProcessId() {
		return processId;
	}

	public void setProcessId(Long processId) {
		this.processId = processId;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	private Document getPropertiesPanel() {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBComponentProperties(),true);
	}

	private Document getViewPanel() {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBViewPanel("viewPanel", "formContainer"), false);
	}

	public Document[] switchView(String view) {
		setView(view);

		ComponentPropertyManager propertyManager = (ComponentPropertyManager) WFUtil.getBeanInstance(ComponentPropertyManager.BEAN_ID);
		propertyManager.resetComponent();

		Document[] result = {getViewPanel(), getPropertiesPanel()};

		return result;

	}

	public Document getDesignView() {
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBDesignView("formElement"), false);
	}

	public Document getWorkspace(String langCode) {
		this.locale = LocaleUtil.getLocale(langCode);
		this.view = FBViewPanel.DESIGN_VIEW;
		return BuilderLogic.getInstance().getRenderedComponent(CoreUtil.getIWContext(), new FBWorkspace("mainWorkspace"), false);
	}

	public Class<FormSourceDownloader> getFormSourceDownloaderClass() {
		return FormSourceDownloader.class;
	}

	public String getFormSourceDownloaderClassName() {
		return getFormSourceDownloaderClass().getName();
	}

	public String getJavaScriptSources() {
		StringBuilder js = new StringBuilder(CoreConstants.DWR_UTIL_SCRIPT).append(CoreConstants.COMMA).append(CoreConstants.DWR_ENGINE_SCRIPT)
			.append(CoreConstants.COMMA).append("/dwr/interface/FormComponent.js,/dwr/interface/PropertyManager.js,/dwr/interface/FormDocument.js,")
			.append("/dwr/interface/FormPage.js,/dwr/interface/ProcessData.js,/dwr/interface/Workspace.js,");
		try {
			js.append(web2.getBundleURIToMootoolsLib()).append(CoreConstants.COMMA).append(web2.getBundleUriToSmoothboxScript()).append(CoreConstants.COMMA);
			js.append(web2.getMoodalboxScriptFilePath(true)).append(CoreConstants.COMMA).append(web2.getBundleUriToInlineEditScript()).append(CoreConstants.COMMA);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		js.append(web2.getBundleUriToMootabsScript()).append(CoreConstants.COMMA).append(jQuery.getBundleURIToJQueryLib()).append(CoreConstants.COMMA);

		IWBundle web2Bundle = IWMainApplication.getDefaultIWMainApplication().getBundle(Web2BusinessBean.WEB2_BUNDLE_IDENTIFIER);
		String basePath = "javascript/jquery-ui/1.8.17/";
		js.append(web2Bundle.getVirtualPathWithFileNameString(new StringBuilder(basePath).append("ui.core.js").toString())).append(CoreConstants.COMMA);
		js.append(web2Bundle.getVirtualPathWithFileNameString(new StringBuilder(basePath).append("ui.widget.js").toString())).append(CoreConstants.COMMA);
		js.append(web2Bundle.getVirtualPathWithFileNameString(new StringBuilder(basePath).append("ui.mouse.js").toString())).append(CoreConstants.COMMA);
		js.append(web2Bundle.getVirtualPathWithFileNameString(new StringBuilder(basePath).append("ui.draggable.js").toString())).append(CoreConstants.COMMA);
		js.append(web2Bundle.getVirtualPathWithFileNameString(new StringBuilder(basePath).append("ui.sortable.js").toString())).append(CoreConstants.COMMA);

		js.append(web2.getBundleUriToHumanizedMessagesScript()).append(CoreConstants.COMMA);

		js.append(IWMainApplication.getDefaultIWMainApplication().getBundle(org.chiba.web.IWBundleStarter.BUNDLE_IDENTIFIER)
				.getVirtualPathWithFileNameString("javascript/PresentationContext.js")).append(CoreConstants.COMMA);
		js.append(IWMainApplication.getDefaultIWMainApplication().getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER)
				.getVirtualPathWithFileNameString("javascript/FormBuilderHelper.js"));

		return js.toString();
	}

	public String getStyleSheetSources() {
		StringBuilder css = new StringBuilder(IWMainApplication.getDefaultIWMainApplication().getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER)
				.getVirtualPathWithFileNameString("style/formbuilder.css")).append(CoreConstants.COMMA);

		try {
			css.append(web2.getBundleUriToSmoothboxStylesheet()).append(CoreConstants.COMMA).append(web2.getMoodalboxStyleFilePath()).append(CoreConstants.COMMA);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		css.append(web2.getBundleUriToHumanizedMessagesStyleSheet()).append(CoreConstants.COMMA).append(web2.getBundleUriToMootabsStyle());

		return css.toString();
	}

} public class FBUtil {
	
	private FBUtil() { }
	
	public static String getPropertyString(String value) {
		return value == null ? FBConstants.NO_VALUE : value;
	}
	
	public static IWBundle getBundle(){
		return getBundle(FacesContext.getCurrentInstance());
	}

	public static IWBundle getBundle(FacesContext context){
		return IWContext.getIWContext(context).getIWMainApplication().getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER);
	}
	
	public static IWResourceBundle getResourceBundle(FacesContext context){
		return getBundle(context).getResourceBundle(context.getExternalContext().getRequestLocale());
	}
	
	public static IWResourceBundle getResourceBundle(){
		return getResourceBundle(FacesContext.getCurrentInstance());
	}
	
	public static String getResourceAbsolutePath(IWMainApplication iwma, String url) {
		IWBundle iwb = iwma.getBundle(IWBundleStarter.IW_BUNDLE_IDENTIFIER);
        return iwb.getRealPathWithFileNameString(url);
	}
	
	/**
	 *
	 * @deprecated - use generateFormId from FormsService 
	 * 
	 */
	@Deprecated
	public static String generateFormId(String name) {
		
		String result = name+"-"+ new Date();
		return result.replace(' ', '_').replace(':', '_');
	}
	
	private static String webdav_server_url;
	
	public static String getWebdavServerUrl(FacesContext ctx) {
		
		if(webdav_server_url == null)
			webdav_server_url = new IWSlideServiceBean().getWebdavServerURL().toString();
		
		return webdav_server_url;
	}

	public static Locale getUILocale() {
		Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);
		Locale locale = workspace.getLocale();
		if(locale == null) {
			locale = CoreUtil.getIWContext().getCurrentLocale();
		}
		return locale;
	}
}
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import com.idega.chiba.web.xml.xforms.validation.ErrorType;
import com.idega.formbuilder.presentation.FBComponentBase;
import com.idega.formbuilder.presentation.beans.ComponentPropertyManager;
import com.idega.formbuilder.presentation.beans.DataSourceList;
import com.idega.formbuilder.presentation.beans.FormButton;
import com.idega.formbuilder.presentation.beans.FormComponent;
import com.idega.formbuilder.presentation.beans.FormMultiUploadComponent;
import com.idega.formbuilder.presentation.beans.FormPlainComponent;
import com.idega.formbuilder.presentation.beans.FormSelectComponent;
import com.idega.formbuilder.presentation.beans.GenericComponent;
import com.idega.formbuilder.presentation.beans.Workspace;
import com.idega.formbuilder.util.FBUtil;
import com.idega.presentation.IWContext;
import com.idega.presentation.Layer;
import com.idega.presentation.text.Text;
import com.idega.presentation.ui.CheckBox;
import com.idega.presentation.ui.Label;
import com.idega.presentation.ui.RadioButton;
import com.idega.presentation.ui.RadioGroup;
import com.idega.presentation.ui.SelectDropdown;
import com.idega.presentation.ui.SelectOption;
import com.idega.presentation.ui.TextArea;
import com.idega.presentation.ui.TextInput;
import com.idega.util.CoreConstants;
import com.idega.util.CoreUtil;
import com.idega.webface.WFUtil;
import com.idega.xformsmanager.business.component.Button;
import com.idega.xformsmanager.business.component.Component;
import com.idega.xformsmanager.business.component.ComponentSelect;
import com.idega.xformsmanager.business.component.ComponentStatic;
import com.idega.xformsmanager.business.component.properties.PropertiesButton;
import com.idega.xformsmanager.business.component.properties.PropertiesComponent;
import com.idega.xformsmanager.business.component.properties.PropertiesStatic;
import com.idega.xformsmanager.util.FormManagerUtil;
package com.idega.formbuilder.presentation.components;




public class FBComponentProperties extends FBComponentBase {

	public static final String COMPONENT_TYPE = "ComponentPropertiesPanel";

	private static final String PROPERTIES_PANEL_SECTION_STYLE = "fbPropertiesPanelSection";
	private String componentId;
	private String componentType;
	private GenericComponent component;

	private static final String SINGLE_LINE_PROPERTY = "fbSingleLineProperty";
	private static final String TWO_LINE_PROPERTY = "fbTwoLineProperty";
	private static final String COMP_LAYER_ID = "fbComponentPropertiesPanel";
	private static final String PLAIN_PROPERTIES_PANEL = "plainPropertiesPanel";
	private static final String FB_PROPERTY_CLASS = "fbProperty";
	private static final String PROPERTY_PLAIN_TEXT_NAME = "propertyPlaintext";
	private static final String PROPERTY_LABEL_NAME = "propertyLabel";
	private static final String LABEL_PROPERTIES_PANEL = "labelPropertiesPanel";
	private static final String PROPERTY_REQUIRED_ID = "propertyRequired";

	private static final String PROPERTY_HELP_TEXT_NAME = "propertyHelpText";
	private static final String PROPERTY_AUTOFILL_CHECKBOX = "propertyHasAutofill";
	private static final String PROPERTY_CALCULATE = "propertyCalc";
	private static final String PROPERTY_USE_HTML_EDITOR = "propertyUseHtmlEditor";

	public String getComponentId() {
		return componentId;
	}

	public void setComponentId(String componentId) {
		this.componentId = componentId;
	}

	public FBComponentProperties() {
		this(null, null);
	}

	public FBComponentProperties(GenericComponent comp) {
		this.component = comp;
	}

	public FBComponentProperties(String componentId, String componentType) {
		super();
		this.componentId = componentId;
		this.componentType = componentType;
	}

	private Layer createPropertyContainer(String styleClass) {
		Layer body = new Layer(Layer.DIV);
		body.setStyleClass(styleClass);
		body.setStyleClass(FB_PROPERTY_CLASS);

		return body;
	}

	private Layer createPanelSection(String id) {
		Layer body = new Layer(Layer.DIV);
		body.setId(id);
		body.setStyleClass(PROPERTIES_PANEL_SECTION_STYLE);

		return body;
	}

	@Override
	protected void initializeComponent(FacesContext context) {
		IWContext iwc = CoreUtil.getIWContext();
		Workspace workspace = (Workspace) WFUtil.getBeanInstance(Workspace.BEAN_ID);

		Layer layer = new Layer(Layer.DIV);
		layer.setId(COMP_LAYER_ID);

		Layer messageBox = new Layer(Layer.DIV);
		messageBox.setId("propertiesPanelMessageBox");

		Text headline = new Text(getLocalizedString(iwc, "labels_properties_disabled", "No selected component"));
		messageBox.add(headline);

		String view = workspace.getView();
		if(FBViewPanel.DESIGN_VIEW.equals(view)) {
			if(component == null) {
				messageBox.setStyleAttribute("display", "block");
			} else {
				messageBox.setStyleAttribute("display", "none");
			}
		} else {
			messageBox.setStyleAttribute("display", "block");
		}

		layer.add(messageBox);

		Locale locale = FBUtil.getUILocale();

		if(component instanceof FormPlainComponent) {