/** * 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 }
PropertyValue propertyValue = it.next(); DesignComponent dcSceneItemComp = propertyValue.getComponent(); dcSceneItemComp.removeFromParentComponent();
public static DesignComponent updateEventHandlerWithNew(DesignComponent eventSource, DesignComponent newEventHandler) { assert newEventHandler == null || newEventHandler.getDocument().getDescriptorRegistry().isInHierarchy(EventHandlerCD.TYPEID, newEventHandler.getType()); DesignComponent oldEventHandler = eventSource.readProperty(EventSourceCD.PROP_EVENT_HANDLER).getComponent(); if (oldEventHandler == newEventHandler) return oldEventHandler; if (oldEventHandler != null) { oldEventHandler.writeProperty(EventHandlerCD.PROP_EVENT_SOURCE, PropertyValue.createNull()); oldEventHandler.removeFromParentComponent(); } if (newEventHandler != null) { eventSource.addComponent(newEventHandler); eventSource.writeProperty(EventSourceCD.PROP_EVENT_HANDLER, PropertyValue.createComponentReference(newEventHandler)); newEventHandler.writeProperty(EventHandlerCD.PROP_EVENT_SOURCE, PropertyValue.createComponentReference(eventSource)); } else { eventSource.writeProperty(EventSourceCD.PROP_EVENT_HANDLER, PropertyValue.createNull()); } return newEventHandler; }