/** * Returns a set of selected components. * @return the set of selected components. */ public Collection<DesignComponent> getSelectedComponents () { assert transactionManager.isAccess (); return selectedComponents; }
/** * Returns an id of the last source that set the current selection. * @return the source id */ public String getSelectionSourceID () { assert transactionManager.isAccess (); return selectionSourceID; }
/** * Returns a component with specified component id. * @param componentID the component id * @return the component */ public DesignComponent getComponentByUID (long componentID) { assert transactionManager.isAccess (); TimedWeakReference ref = uid2components.get (componentID); return ref != null ? ref.get () : null; }
/** * Returns a component descriptor. * @return the compatible descriptor, null if not assigned */ public ComponentDescriptor getComponentDescriptor() { assert document.getTransactionManager().isAccess(); return componentDescriptor; }
/** * Returns a root component of components tree assigned to the document. * @return the root component. */ public DesignComponent getRootComponent () { assert getTransactionManager ().isAccess (); return rootComponent; }
/** * Returns a parent component of this component. * @return the parent component */ public DesignComponent getParentComponent() { assert document.getTransactionManager().isAccess(); return parentComponent; }
/** * Returns a presenter for a specific presenter id. * @param presenterClass the presenter class * @return the presenter */ public <T extends Presenter> T getPresenter(Class<T> presenterClass) { assert document.getTransactionManager().isAccess(); assert presenterClass != null; return presenters.lookup(presenterClass); }
/** * Returns a list of presenters in a specific presenter category. * A presenter matches when the specified presenter category is a prefix of the id of the presenter. * @param presenterClass the presenter category class * @return a collection of presenters, non-null value */ public <T> Collection<? extends T> getPresenters(Class<T> presenterClass) { assert document.getTransactionManager().isAccess(); assert presenterClass != null; return presenters.lookupAll(presenterClass); }
/** * Returns a collection of children components. * @return the collection of children */ public Collection<DesignComponent> getComponents() { assert document.getTransactionManager().isAccess(); return Collections.unmodifiableCollection(children); }
public DesignComponent getEditedScreen() { assert SwingUtilities.isEventDispatchThread(); assert document.getTransactionManager().isAccess(); return editedScreen; }
/** * Resolves whether a specified property has a default value as current value. * Check is done on the PropertyValue object level. This method returns true only when DesignComponent * default PropertyValue == current PropertyValue for given propertyName. * @param propertyName the property name * @return true if a current PropertyValue is the same PropertyValue object which has been created on the creation of the DesignComponent */ public boolean isDefaultValue(String propertyName) { assert document.getTransactionManager().isAccess(); assert propertyName != null; PropertyValue defaultValue = defaultProperties.get(propertyName); PropertyValue currentValue = properties.get(propertyName); assert defaultValue != null; assert currentValue != null; //This has to be changed in previous version, it should be resolved on the "equals" method level. return defaultValue == currentValue; }
/** * Returns a property value of a specified property * @param propertyName the property name * @return the property value */ public PropertyValue readProperty(String propertyName) { assert document.getTransactionManager().isAccess(); PropertyValue value = properties.get(propertyName); assert properties.containsKey(propertyName) : toString () + "." + propertyName + " property is missing"; //NOI18N assert value != null; return value; }
void dumpComponent(String indent) { assert document.getTransactionManager().isAccess(); System.out.println(indent + componentID + " : " + componentDescriptor); // NOI18N indent += " "; // NOI18N HashSet<String> undefinedProperties = new HashSet<String> (properties.keySet()); Collection<PropertyDescriptor> propertyDescriptors = componentDescriptor.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String name = property.getName(); System.out.println(indent + (properties.get(name) == defaultProperties.get(name) ? "## " : ":: ") + name + " = " + properties.get(name)); // NOI18N undefinedProperties.remove(name); } for (String name : undefinedProperties) System.out.println(indent + "?? " + name + " = " + properties.get(name)); // NOI18N for (Object presenter : presenters.lookupAll(Object.class)) System.out.println(indent + ">>" + presenter); // NOI18N for (DesignComponent child : children) child.dumpComponent(indent); }
/** * Return all editable screens in the document. * Call this method within the read or write access only. * @param document the design document * @return the list of all editable screens in the document. */ public static List<DesignComponent> getAllEditableScreensInDocument(DesignDocument document) { assert document.getTransactionManager().isAccess(); ArrayList<DesignComponent> screens = new ArrayList<DesignComponent> (); for (DesignComponent component : DocumentSupport.gatherAllComponentsContainingPresenterClass(document, ScreenDisplayPresenter.class)) { if (component.getPresenter(ScreenDisplayPresenter.class).isTopLevelDisplay()) screens.add(component); } return screens; }
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); }
static String getGetterName(final DesignComponent component, final String fieldName) { if (fieldName == null || fieldName.length() == 0) { return ""; } if (component.getDocument().getTransactionManager().isAccess()) { String accessCode = CodeReferencePresenter.generateAccessCode(component, fieldName); if (!accessCode.equals(fieldName)) { String methodName = accessCode.replace("()", ""). // NOI18N trim(); if (accessCode.startsWith(methodName)) { return methodName; } } return null; } else { final String[] result = new String[1]; component.getDocument().getTransactionManager().readAccess( new Runnable() { public void run() { result[0] = getGetterName(component, fieldName); } }); return result[0]; } }
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); }