/** * Sets a preferred component ID. * <p> * Warning: This method is for deserialization purpose only (IO module). Do not use it directly. * @param preferredComponentID the preferred component id * @return true if preferred component id was used */ public boolean setPreferredComponentID (long preferredComponentID) { assert transactionManager.isWriteAccess (); if (componentIDCounter > preferredComponentID) return false; componentIDCounter = preferredComponentID; return true; }
/** * Reset a specific property to its default value. * @param propertyName the property name */ public void resetToDefault(String propertyName) { assert document.getTransactionManager().isWriteAccess (); assert propertyName != null; PropertyValue defaultValue = defaultProperties.get(propertyName); assert defaultValue != null; writeProperty(propertyName, defaultValue); }
/** * Sets selected components. It requires to specify a source id for identifying the source of the selection. * <p> * Note: Undo/redo of setSelectedComponents changed will use null as a selectionSourceID * @param selectionSourceID the source id * @param components the set of selected components. */ public void setSelectedComponents (String selectionSourceID, Collection<DesignComponent> components) { assert transactionManager.isWriteAccess (); assert components != null; assert setSelectedComponentsAssert (components); if (this.selectedComponents.containsAll (components) && components.containsAll (this.selectedComponents)) return; Collection<DesignComponent> old = this.selectedComponents; this.selectionSourceID = selectionSourceID; this.selectedComponents = Collections.unmodifiableCollection (new ArrayList<DesignComponent> (components)); transactionManager.selectComponentsHappened (old, this.selectedComponents); }
/** * Removes the component from its parent component. */ public void removeFromParentComponent () { assert document.getTransactionManager ().isWriteAccess (); if (parentComponent != null) parentComponent.removeComponent (this); }
public static DesignComponent getCategoryComponent(DesignDocument document, TypeID categoryType) { List<DesignComponent> list = DocumentSupport.gatherSubComponentsOfType(document.getRootComponent(), categoryType); if (list.size () == 0 && document.getTransactionManager ().isWriteAccess ()) { DesignComponent categoryComponent = document.createComponent (categoryType); document.getRootComponent ().addComponent (categoryComponent); return categoryComponent; } assert list.size() == 1; return list.get(0); }
/** * Sets a root component of the document. This method could be called only once. * <p> * Warning: This method should be used by IO module (where the document is created) only. * @param rootComponent the root component */ public void setRootComponent (DesignComponent rootComponent) { assert getTransactionManager ().isWriteAccess (); assert this.rootComponent == null; assert rootComponent != null; this.rootComponent = rootComponent; getTransactionManager ().rootChangeHappened (rootComponent); }
/** * Adds an undoable edit into a undo-redo queue. * <p> * Note: use this to add an additional undoable edit that cannot be produces by the model directly. * <p> * @param edit the edit; for whole edit instance lifecycle, it has to: edit.isSignificant must return false, edit.canUndo and edit.canRedo must return true, edit.undo and edit.redo must not throw any exception. */ public void undoableEditHappened (UndoableEdit edit) { assert isWriteAccess (); assert ! edit.isSignificant (); if (transactionEdit == null) transactionEdit = new TransactionEdit (); transactionEdit.addEdit (edit); }
/** * Adds a child component into this component. * @param component the child component */ public void addComponent(DesignComponent component) { assert document.getTransactionManager().isWriteAccess(); assert document == component.document; assert component.parentComponent == null; assert addComponentAssert (component); children.add(component); component.parentComponent = this; document.getTransactionManager().parentChangeHappened(null, this, component); }
/** * Removes a child component from this component. * @param component the child component */ public void removeComponent(DesignComponent component) { assert document.getTransactionManager().isWriteAccess(); assert document == component.document; assert component.parentComponent == this; if (! children.remove(component)) throw Debug.error ("Component is not a child of its parent", "parent", this, "Child", component, "Children", children); // NOI18N component.parentComponent = null; document.getTransactionManager().parentChangeHappened(this, null, component); }
/** * Writes a property value. * @param propertyName the property name * @param propertyValue the property value */ public void writeProperty(String propertyName, PropertyValue propertyValue) { assert document.getTransactionManager().isWriteAccess(); assert propertyValue != null : "Null property value"; // NOI18N assert componentDescriptor != null; PropertyValue oldValue = properties.get(propertyName); assert oldValue != null : "Missing old value in " + this + "." + propertyName; // NOI18N if (oldValue == propertyValue) return; PropertyDescriptor propertyDescriptor = componentDescriptor.getPropertyDescriptor(propertyName); assert propertyDescriptor != null : "Missing property descriptor in " + this + "." + propertyName; // NOI18N assert ! propertyDescriptor.isReadOnly() : "Cannot write read-only property " + this + "." + propertyName; // NOI18N // TODO - allow writing during deserialization assert propertyValue.isCompatible(propertyDescriptor); properties.put(propertyName, propertyValue); document.getTransactionManager().writePropertyHappened(this, propertyName, oldValue, propertyValue); }
/** * This method should be called for notifying others that the presenter changed its data. * <p/> * Note: This method could be called from designChanged and presenterChanged method only. */ protected final void firePresenterChanged () { DesignComponent component = getComponent (); assert component != null; DesignDocument document = component.getDocument (); assert document != null; assert document.getTransactionManager ().isWriteAccess (); assert state == State.FIRING_PRESENTER_CHANGED; document.getListenerManager ().firePresenterChanged (this); }
/** * Removes a component from the component tree and removes references to this component from all property values * in all components in the document. * <p> * Note: It does not allows to remove the root component. * @param component the component */ public void deleteComponent (DesignComponent component) { assert transactionManager.isWriteAccess (); assert component != null && component != rootComponent; assert component.getDocument () == this; Collection<DesignComponent> components = component.getComponents (); if (components.size () > 0) Debug.warning ("Children has to be deleted before deleting the component", component, components); // NOI18N component.removeFromParentComponent (); ComponentDescriptor descriptor = component.getComponentDescriptor (); if (descriptor != null) for (PropertyDescriptor property : descriptor.getPropertyDescriptors ()) component.resetToDefault (property.getName ()); if (selectedComponents.contains (component)) { HashSet<DesignComponent> selected = new HashSet<DesignComponent> (selectedComponents); selected.remove (component); setSelectedComponents ("deleteComponent", selected); // NOI18N } assert ! Debug.isComponentReferencedInRootTree (component) : "Component (" + component + ") is referenced still after deletion"; // NOI18N }
assert transactionManager.isWriteAccess (); assert deleteComponentsPreAssert (components);
/** * Creates a new raw component using a component descriptor with specified typeid. * <p> * Note: It does not add the component into a tree, you have to do it manually. * <p> * Note: it just allocates the component, it does not do any post-initializion. * @param componentType the component typeid * @return the new raw component */ public DesignComponent createRawComponent (TypeID componentType) { assert Debug.isFriend (DesignDocument.class, "createComponent") || Debug.isFriend ("org.netbeans.modules.vmd.io.DocumentLoad", "loadDocumentCore"); // NOI18N assert transactionManager.isWriteAccess (); ComponentDescriptor componentDescriptor = descriptorRegistry.getComponentDescriptor (componentType); assert componentDescriptor != null : "Missing component descriptor for " + componentType; // NOI18N assert componentDescriptor.getTypeDescriptor ().isCanInstantiate (); DesignComponent component = new DesignComponent (this, componentIDCounter ++, componentDescriptor); uid2components.put (component.getComponentID (), new TimedWeakReference (component)); getListenerManager ().notifyComponentCreated (component); return component; }
if (component.getDocument().getTransactionManager().isWriteAccess()) Debug.warning("Calling PropertiesSupport.showPropertyEditorForCurrentComponent form write transaction may generate problems"); //NOI18N DataEditorView view = ActiveViewSupport.getDefault().getActiveView();