private DesignComponent getCommandEvenSource(final String name) { final DesignComponent[] itemCommandEvenSource = new DesignComponent[1]; if (component != null && component.get() != null) { final DesignComponent listComponent = component.get(); listComponent .getDocument() .getTransactionManager() .writeAccess( new Runnable() { public void run() { DesignComponent command = values.get(name); List<PropertyValue> listESValues = listComponent.readProperty(DisplayableCD.PROP_COMMANDS).getArray(); for (PropertyValue esValue : listESValues) { DesignComponent existingES = esValue.getComponent(); if (existingES .readProperty(CommandEventSourceCD.PROP_COMMAND) .getComponent() .equals(command)) { itemCommandEvenSource[0] = existingES; break; } } if (itemCommandEvenSource[0] == null) { // create new ItemCommandEvenSource itemCommandEvenSource[0] = MidpDocumentSupport.attachCommandToDisplayable(listComponent, command); } } }); } return itemCommandEvenSource[0]; }
public static PropertyValue createFromSuggested( DesignComponent component, String suggestedMainName, Collection<String> additionalReservedNames) { assert component.getDocument().getTransactionManager().isAccess(); Collection<? extends CodeNamePresenter> presenters = component.getPresenters(CodeNamePresenter.class); if (presenters.isEmpty()) Debug.warning("CodeNamePresenter is missing for", component); // NOI18N HashSet<String> names = new HashSet<String>(); gatherNames(component.getDocument().getRootComponent(), component, names); if (additionalReservedNames != null) names.addAll(additionalReservedNames); suggestedMainName = checkForJavaIdentifierCompliant(suggestedMainName); if (checkIfNameAlreadyReserved(presenters, suggestedMainName, names)) { int index = suggestedMainName.length(); while (index >= 1 && Character.isDigit(suggestedMainName.charAt(index - 1))) index--; int number = index < suggestedMainName.length() ? Integer.parseInt(suggestedMainName.substring(index)) : 1; suggestedMainName = suggestedMainName.substring(0, index); suggestedMainName = findNumberedInstanceName(presenters, suggestedMainName, number, names); } return MidpTypes.createStringValue(suggestedMainName); }
public void setValue(final PropertyValue value) { if (value == null) { combobox.setSelectedItem(noneItem); return; } final PropertyValue[] cmdValue = new PropertyValue[1]; if (component != null && component.get() != null) { final DesignDocument document = component.get().getDocument(); document .getTransactionManager() .readAccess( new Runnable() { public void run() { cmdValue[0] = value.getComponent().readProperty(CommandEventSourceCD.PROP_COMMAND); } }); } if (cmdValue[0] == null) { return; } DesignComponent command = cmdValue[0].getComponent(); for (String key : values.keySet()) { DesignComponent tmpCommand = values.get(key); if (tmpCommand != null && tmpCommand.equals(command)) { combobox.setSelectedItem(key); break; } } }
@Override public void reload(ScreenDeviceInfo deviceInfo) { super.reload(deviceInfo); JPanel contentPanel = getPanel().getContentPanel(); contentPanel.removeAll(); GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1.0; constraints.weightx = 1.0; constraints.fill = GridBagConstraints.BOTH; constraints.gridx = GridBagConstraints.REMAINDER; constraints.gridy = GridBagConstraints.RELATIVE; constraints.anchor = GridBagConstraints.NORTHWEST; for (DesignComponent item : getChildren()) { ScreenDisplayPresenter presenter = item.getPresenter(ScreenDisplayPresenter.class); if (presenter == null) { continue; } contentPanel.add(presenter.getView(), constraints); presenter.reload(deviceInfo); } constraints.weighty = 1.0; constraints.anchor = GridBagConstraints.CENTER; contentPanel.add(fillPanel, constraints); }
private static void gatherNames( DesignComponent component, DesignComponent excludeComponent, HashSet<String> names) { assert component.getDocument().getTransactionManager().isAccess(); if (component == excludeComponent) return; Collection<? extends CodeNamePresenter> presenters = component.getPresenters(CodeNamePresenter.class); for (CodeNamePresenter presenter : presenters) { List<String> reservedNames = presenter.getReservedNames(); if (reservedNames != null) names.addAll(reservedNames); } for (DesignComponent child : component.getComponents()) gatherNames(child, excludeComponent, names); }
protected Item createItem(DesignComponent designComponent, ResourcesProvider resourcesProvider) { String text = null; int appearanceMode = StringItem.PLAIN; PropertyValue value = designComponent.readProperty(StringItemCD.PROP_TEXT); if (value.getKind() == PropertyValue.Kind.VALUE) { text = MidpTypes.getString(value); } else { System.out.println("Unable to retrieve text - Kind=" + value.getKind()); text = "default"; } value = designComponent.readProperty(StringItemCD.PROP_APPEARANCE_MODE); if (value.getKind() == PropertyValue.Kind.VALUE) { appearanceMode = MidpTypes.getInteger(value); } return new StringItem(null, text, appearanceMode); }
@Override public void generateParameterCode( DesignComponent component, MultiGuardedSection section, int index) { PropertyValue value = component.readProperty(PROP_CONSTRAINTS); if (value.getKind() == PropertyValue.Kind.VALUE) { int constraint = MidpTypes.getInteger(value); int core = constraint & TextFieldCD.VALUE_CONSTRAINT_MASK; CodeWriter writer = section.getWriter(); switch (core) { case TextFieldCD.VALUE_ANY: writer.write("TextField.ANY"); // NOI18N break; case TextFieldCD.VALUE_EMAILADDR: writer.write("TextField.EMAILADDR"); // NOI18N break; case TextFieldCD.VALUE_NUMERIC: writer.write("TextField.NUMERIC"); // NOI18N break; case TextFieldCD.VALUE_PHONENUMBER: writer.write("TextField.PHONENUMBER"); // NOI18N break; case TextFieldCD.VALUE_URL: writer.write("TextField.URL"); // NOI18N break; case TextFieldCD.VALUE_DECIMAL: writer.write("TextField.DECIMAL"); // NOI18N break; default: writer.write(Integer.toString(core)); } if ((constraint & TextFieldCD.VALUE_PASSWORD) != 0) { writer.write(" | TextField.PASSWORD"); // NOI18N } if ((constraint & TextFieldCD.VALUE_UNEDITABLE) != 0) { writer.write(" | TextField.UNEDITABLE"); // NOI18N } if ((constraint & TextFieldCD.VALUE_SENSITIVE) != 0) { writer.write(" | TextField.SENSITIVE"); // NOI18N } if ((constraint & TextFieldCD.VALUE_NON_PREDICTIVE) != 0) { writer.write(" | TextField.NON_PREDICTIVE"); // NOI18N } if ((constraint & TextFieldCD.VALUE_INITIAL_CAPS_WORD) != 0) { writer.write(" | TextField.INITIAL_CAPS_WORD"); // NOI18N } if ((constraint & TextFieldCD.VALUE_INITIAL_CAPS_SENTENCE) != 0) { writer.write(" | TextField.INITIAL_CAPS_SENTENCE"); // NOI18N } return; } super.generateParameterCode(component, section, index); }
private String getDecodeValue(final PropertyValue value) { final String[] decodeValue = new String[1]; final DesignComponent valueComponent = value.getComponent(); if (valueComponent != null) { final DesignDocument document = valueComponent.getDocument(); if (document != null) { document .getTransactionManager() .readAccess( new Runnable() { public void run() { DesignComponent valueComponent = value.getComponent(); if (valueComponent != null) { PropertyValue pv = valueComponent.readProperty(CommandEventSourceCD.PROP_COMMAND); if (pv != null) { DesignComponent refComponent = pv.getComponent(); if (refComponent != null && refComponent.equals(getListSelectCommand(document))) { decodeValue[0] = defaultItem; } else { decodeValue[0] = getComponentDisplayName(valueComponent); } } else { decodeValue[0] = noneItem; } } else { decodeValue[0] = noneItem; } } }); } } return decodeValue[0]; }
@Override public DesignComponent createComponent(DesignComponent parentComponent) { DesignComponent dc = parentComponent.getDocument().createComponent(getTypeID()); if (myEventType != null) { DesignComponent svgES = parentComponent.getDocument().createComponent(myEventType); svgES.writeProperty( SVGComponentEventSourceCD.PROP_SVGCOMPONENT, PropertyValue.createComponentReference(dc)); parentComponent.addComponent(svgES); } dc.writeProperty(SVGComponentCD.PROP_ID, MidpTypes.createStringValue(getId())); Map<String, Object> properties = getProperties(); if (properties != null) { for (Entry<String, Object> entry : properties.entrySet()) { if (!entry.getKey().equals(SVGRadioButtonCD.PROP_BUTTON_GROUP)) { dc.writeProperty( entry.getKey(), MidpTypes.createStringValue(entry.getValue().toString())); } } } return dc; }
public static synchronized void parseSVGForm( final InputStream svgInputStream, final DesignComponent svgForm) { final SVGFormComponent[] srcComponents = getFormComponents(svgInputStream); if (srcComponents != null) { svgForm .getDocument() .getTransactionManager() .writeAccess( new Runnable() { public void run() { Map<SVGFormComponent, DesignComponent> producer2Component = new HashMap<SVGFormComponent, DesignComponent>(); for (SVGFormComponent srcComponent : srcComponents) { DesignComponent svgComponent = srcComponent.createComponent(svgForm); svgForm.addComponent(svgComponent); producer2Component.put(srcComponent, svgComponent); MidpArraySupport.append(svgForm, SVGFormCD.PROP_COMPONENTS, svgComponent); } initButtonGroup(producer2Component); } }); } }
@Override public void postInitialize(DesignComponent component) { component.writeProperty(PROP_MAX_SIZE, MidpTypes.createIntegerValue(32)); component.writeProperty(PROP_CONSTRAINTS, MidpTypes.createIntegerValue(VALUE_ANY)); }