public void run() { document.getTransactionManager().readAccess(new Runnable() { public void run() { refreshModel(); } }); } });
private void updateDescriptorReferences () { transactionManager.writeAccess (new Runnable () { public void run () { updateDescriptorReferencesCore (); } }); }
/** * Returns a set of selected components. * @return the set of selected components. */ public Collection<DesignComponent> getSelectedComponents () { assert transactionManager.isAccess (); return selectedComponents; }
/** * 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); }
/** * 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); }
/** * 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); }
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]; } }
/** * 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; }
/** * 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); }
void selectComponentsHappened (Collection<DesignComponent> oldSelection, Collection<DesignComponent> newSelection) { assert Debug.isFriend (DesignDocument.class, "setSelectedComponents"); // NOI18N assert assertEventAllowed; listenerManager.setSelectionChanged (); undoableEditHappened (new SelectionEdit (document, oldSelection, newSelection)); }
/** * Creates an instance of document. * @param documentInterface the documentInterface interface */ public DesignDocument (DocumentInterface documentInterface) { this.documentInterface = documentInterface; descriptorRegistry = DescriptorRegistry.getDescriptorRegistry (documentInterface.getProjectType (), documentInterface.getProjectID ()); listenerManager = new ListenerManager (this); transactionManager = new TransactionManager (this, descriptorRegistry, listenerManager); uid2components = new HashMap<Long, TimedWeakReference> (100); componentIDCounter = 0; selectedComponents = Collections.emptySet (); descriptorRegistry.addRegistryListener (new DescriptorRegistryListener() { public void descriptorRegistryUpdated () { updateDescriptorReferences (); } }); }
/** * 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); }
/** * 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); }
void writePropertyHappened (DesignComponent component, String propertyName, PropertyValue oldValue, PropertyValue newValue) { assert Debug.isFriend (DesignComponent.class, "writeProperty"); // NOI18N assert assertEventAllowed; listenerManager.addAffectedDesignComponent (component, propertyName, oldValue); undoableEditHappened (new WritePropertyEdit (component, propertyName, oldValue, newValue)); }
public void actionPerformed(ActionEvent e) { document.getTransactionManager().readAccess(new Runnable() { public void run() { DesignComponent component = (DesignComponent) editedScreenCombo.getSelectedItem(); EditedScreenSupport.getSupportForDocument(document).setEditedScreenComponentID(component != null ? component.getComponentID() : -1); } }); } };
public void run () { transactionManager.writeAccess (new Runnable() { public void run () { uid2components.remove (componentID); } }); } }
/** * Returns an id of the last source that set the current selection. * @return the source id */ public String getSelectionSourceID () { assert transactionManager.isAccess (); return selectionSourceID; }
/** * Removes the component from its parent component. */ public void removeFromParentComponent () { assert document.getTransactionManager ().isWriteAccess (); if (parentComponent != null) parentComponent.removeComponent (this); }
void parentChangeHappened (DesignComponent previousParent, DesignComponent parent, DesignComponent child) { assert Debug.isFriend (DesignComponent.class, "addComponent") || Debug.isFriend (DesignComponent.class, "removeComponent"); // NOI18N assert assertEventAllowed; listenerManager.addAffectedComponentHierarchy (previousParent); listenerManager.addAffectedComponentHierarchy (parent); listenerManager.addAffectedComponentHierarchy (child); undoableEditHappened (new SetParentEdit (previousParent, parent, child)); }
public void run () { if (designDocument != null) { designDocument.getTransactionManager ().readAccess (new Runnable () { public void run () { ScreenAccessController accessController = designDocument.getListenerManager ().getAccessController (ScreenAccessController.class); if (accessController != null) accessController.setScreenSize (deviceScreenSize); } }); } } });