/** * Remove the EditorIcons defined for the entity. * * @param entity The entity. * @return true if at least one EditorIcon is found and removed; false otherwise. * @exception KernelException If error occurs while removing the EditorIcons. */ private static boolean _removeEditorIcons(GTEntity entity) throws KernelException { NamedObj object = (NamedObj) entity; boolean foundPersistentIcon = false; try { object.workspace().getReadAccess(); for (Object iconObject : object.attributeList(EditorIcon.class)) { EditorIcon icon = (EditorIcon) iconObject; if (icon.isPersistent()) { foundPersistentIcon = true; } else { icon.setContainer(null); } } } finally { object.workspace().doneReading(); } return !foundPersistentIcon; }
/** * Execute the change request by retrieving the icon description or EditorIcon of the single * entity in the container given in the constructor and copying it to the entity given in the * constructor. * * @exception Exception If the icon cannot be retrieved, or it cannot be associated with the * entity. */ protected void _execute() throws Exception { ComponentEntity actor; try { _container.workspace().getReadAccess(); actor = (ComponentEntity) _container.entityList().get(0); } finally { _container.workspace().doneReading(); } if (!_removeEditorIcons(_entity)) { return; } ConfigurableAttribute actorAttribute = (ConfigurableAttribute) actor.getAttribute("_iconDescription"); String iconDescription = actorAttribute.getConfigureText(); _setIconDescription(_entity, iconDescription); try { actor.workspace().getReadAccess(); List<?> editorIconList = actor.attributeList(EditorIcon.class); for (Object editorIconObject : editorIconList) { EditorIcon editorIcon = (EditorIcon) editorIconObject; EditorIcon icon = (EditorIcon) editorIcon.clone(((NamedObj) _entity).workspace()); icon.setName("_icon"); EditorIcon oldIcon = (EditorIcon) ((NamedObj) _entity).getAttribute("_icon"); if (oldIcon != null) { oldIcon.setContainer(null); } icon.setContainer((NamedObj) _entity); icon.setPersistent(false); break; } } finally { actor.workspace().doneReading(); } }
/** * Update the appearance (icons and ports) of the entity with the change in a * GTIngredientAttribute, such as a criterion or an operation. * * @param entity The entity. * @param attribute The attribute whose recent change leads to an update of the entity. */ public static void updateAppearance(final GTEntity entity, GTIngredientsAttribute attribute) { NamedObj object = (NamedObj) entity; Workspace workspace = object.workspace(); try { workspace.getWriteAccess(); List<?> icons = object.attributeList(EditorIcon.class); boolean foundPersistentIcon = false; for (Object iconObject : icons) { EditorIcon icon = (EditorIcon) iconObject; if (icon.isPersistent()) { foundPersistentIcon = true; break; } } Set<String> preservedPortNames = new HashSet<String>(); boolean isIconSet = false; int i = 1; GTIngredientList list = attribute.getIngredientList(); for (GTIngredient ingredient : list) { if (ingredient instanceof PortCriterion) { PortCriterion criterion = (PortCriterion) ingredient; String portID = criterion.getPortID(list); preservedPortNames.add(portID); TypedIOPort port = (TypedIOPort) ((ComponentEntity) entity).getPort(portID); boolean isInput = criterion.isInput(); boolean isOutput = criterion.isOutput(); boolean isMultiport = !criterion.isMultiportEnabled() || criterion.isMultiport(); if (port != null) { if (port instanceof PortMatcher) { port.setInput(isInput); port.setOutput(isOutput); } else { MoMLChangeRequest request = new MoMLChangeRequest( entity, object, "<deletePort name=\"" + port.getName() + "\"/>"); request.setUndoable(true); request.setMergeWithPreviousUndo(true); request.execute(); port = new PortMatcher(criterion, (ComponentEntity) entity, portID, isInput, isOutput); port.setDerivedLevel(1); } } else { port = new PortMatcher(criterion, (ComponentEntity) entity, portID, isInput, isOutput); port.setDerivedLevel(1); } port.setMultiport(isMultiport); } else if (ingredient instanceof SubclassCriterion && !isIconSet && !foundPersistentIcon) { SubclassCriterion criterion = (SubclassCriterion) ingredient; final String superclass = criterion.getSuperclass(); object.requestChange( new ChangeRequest(entity, "Deferred load actor icon action.") { protected void _execute() throws Exception { _loadActorIcon(entity, superclass); } }); isIconSet = true; } i++; } if (!isIconSet && !foundPersistentIcon) { object.requestChange(new RestoreAppearanceChangeRequest(entity)); } ComponentEntity component = (ComponentEntity) entity; try { component.workspace().getReadAccess(); List<?> portList = new LinkedList<Object>(component.portList()); for (i = 0; i < portList.size(); i++) { Port port = (Port) portList.get(i); if (port instanceof PortMatcher && !preservedPortNames.contains(port.getName())) { ((PortMatcher) port)._setPortCriterion(null); port.setContainer(null); } } } finally { component.workspace().doneReading(); } } catch (KernelException e) { throw new KernelRuntimeException( e, "Cannot update appearance for " + "actor " + entity.getName() + "."); } finally { workspace.doneWriting(); } }