public void run() { String keplerprop = System.getProperty("KEPLER"); if (keplerprop == null) { keplerprop = "."; } String configDir = keplerprop + OPENDAP_CONFIG_DIR; DodsURL[] urls = ApplicationController.blockingMain(new String[] {configDir}); if (urls != null) { if (urls.length > 1) { // XXX how is this case possible? log.warn("More than one URL returned from ODC: " + urls.length); } String odcUrl = urls[0].getFullURL(); String urlStr = null; String ceStr = null; int index = odcUrl.indexOf("?"); if (index == -1) { urlStr = odcUrl; } else { urlStr = odcUrl.substring(0, index); ceStr = odcUrl.substring(index + 1); } log.debug("ODC sent url = " + urlStr); try { // first clear the old URL and CE // NOTE: setting a new URL before clearing old CE // will cause a reload, which may not work since // the CE could refer to fields not present in the // new URL. opendapURLParameter.setToken(new StringToken("")); opendapCEParameter.setToken(new StringToken("")); opendapURLParameter.setToken(new StringToken(urlStr)); if (ceStr != null) { opendapCEParameter.setToken(new StringToken(ceStr)); log.debug("ODC sent ce = " + ceStr); } } catch (IllegalActionException e) { log.error(e); } // queue a dummy change request that will cause // the gui to show the new output ports. String buffer = "<group>\n</group>"; MoMLChangeRequest request = new MoMLChangeRequest(this, getContainer(), buffer); request.setPersistent(false); requestChange(request); } }
/** * Execute a MoMLChangeRequest to set the icon description of the attribute. * * @param object The attribute. * @param iconDescription The icon description. */ public static void setIconDescription(NamedObj object, String iconDescription) { String moml = "<property name=\"_iconDescription\" class=" + "\"ptolemy.kernel.util.SingletonConfigurableAttribute\">" + " <configure>" + iconDescription + "</configure>" + "</property>"; MoMLChangeRequest request = new MoMLChangeRequest(object, object, moml); request.execute(); }
/** * Remove all the annotations from the graph. Actors, their ports, and relations are inspected to * see if they either a _color and/or an _explanation attribute. If so, then the attribute is * removed via a MoMl changeRequest. */ public void deAnnotateGraph() { StringBuffer moml = new StringBuffer(); Iterator entities = _model.entityList(ComponentEntity.class).iterator(); while (entities.hasNext()) { ComponentEntity entity = (ComponentEntity) (entities.next()); String entityDeletes = _deletesIfNecessary(entity); moml.append("<entity name=\"" + entity.getName() + "\">"); if (entityDeletes != null) { moml.append(entityDeletes); } Iterator ports = entity.portList().iterator(); while (ports.hasNext()) { Port port = (Port) (ports.next()); String portDeletes = _deletesIfNecessary(port); if (portDeletes != null) { moml.append("<port name=\"" + port.getName() + "\">" + portDeletes + "</port>"); } } moml.append("</entity>"); } Iterator relations = _model.relationList().iterator(); while (relations.hasNext()) { Relation relation = (Relation) (relations.next()); String relationDeletes = _deletesIfNecessary(relation); if (relationDeletes != null) { moml.append( "<relation name=\"" + relation.getName() + "\">" + relationDeletes + "\"/></relation>"); } } if (moml.length() > 0) { String momlUpdate = "<group>" + moml.toString() + "</group>"; MoMLChangeRequest request = new MoMLChangeRequest(this, _model, momlUpdate); request.setUndoable(true); request.setPersistent(false); _model.requestChange(request); } }
/** * Remove all ports by setting their container to null. As a side effect, the ports will be * unlinked from all relations. This method is write-synchronized on the workspace, and increments * its version number. */ public void removeAllPorts() { try { _workspace.getWriteAccess(); // Have to copy _portList to avoid corrupting the iterator. List portListCopy = new LinkedList(portList()); Iterator ports = portListCopy.iterator(); while (ports.hasNext()) { Port port = (Port) ports.next(); try { MoMLChangeRequest request = new MoMLChangeRequest(this, this, "<deletePort name=\"" + port.getName() + "\"/>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { // Ignore. } } } finally { _workspace.doneWriting(); } }
/** * Update the ports to match the arguments. If an Argument has no corresponding port, a Port is * added. If a Port does not have a corresponding Argument, then the Port is removed. If a input * and/or output nature of a Port does not match the Argument with the same name, then the Port is * adjusted. * * @exception IllegalActionException If there is a problem updating the ports. */ public void updatePorts() throws IllegalActionException { Iterator arguments = this.argumentsList().iterator(); TypedIOPort port; while (arguments.hasNext()) { Argument argument = (Argument) arguments.next(); port = (TypedIOPort) this.getPort(argument.getName()); if (port == null) { MoMLChangeRequest request = null; try { if (argument.isReturn()) { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); } else if (argument.isInput() && argument.isOutput()) { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "in" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"input\"/>\n" + "</port>\n" + "<port name=\"" + argument.getName() + "out" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); } else { request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (argument.isInput() ? " <property name=\"input\"/>\n" : "") + (argument.isOutput() ? " <property name=\"output\"/>\n" : "") + "</port>"); } request.setUndoable(true); requestChange(request); } catch (Throwable throwable) { throw new IllegalActionException( this, throwable, "MoMLChangeRequest for \"" + argument.getName() + "\" failed. Request was:\n" + request); } } else { // We have a preexisting port, synchronized the // arguments and the ports. if (argument.isReturn()) { if (port.isInput()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <deleteProperty name=\"input\"/>\n" + (port.isOutput() ? "" : " <property name=\"output\"/>\n") + "</port>"); request.setUndoable(true); requestChange(request); } if (!port.isOutput()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } } else /*if (port.isInput() != argument.isInput() || port.isOutput() != argument.isOutput())*/ { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (port.isInput() ? (argument.isInput() ? "" : "<deleteProperty name=\"input\"/>\n") : (argument.isInput() ? "<property name=\"input\"/>\n" : "")) + (port.isOutput() ? (argument.isOutput() ? "" : "<deleteProperty name=\"output\"/>\n") : (argument.isOutput() ? "<property name=\"output\"/>\n" : "")) + "</port>"); request.setUndoable(true); requestChange(request); } } } // Remove any ports that do not have arguments. Iterator ports = portList().iterator(); while (ports.hasNext()) { port = (TypedIOPort) ports.next(); Argument argument = (Argument) _argumentsList.get(port.getName()); if (argument == null) { MoMLChangeRequest request = new MoMLChangeRequest(this, this, "<deletePort name=\"" + port.getName() + "\"/>"); request.setUndoable(true); requestChange(request); } } }
/** * For each Argument, a port of the same name is created, belonging to this argument. * * @exception IllegalActionException If there is a problem creating the ports. */ public void createPorts() throws IllegalActionException { Iterator arguments = this.argumentsList().iterator(); TypedIOPort port; while (arguments.hasNext()) { Argument argument = (Argument) arguments.next(); port = (TypedIOPort) this.getPort(argument.getName()); if (port == null) { if (argument.isReturn()) { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct port " + "port for argument \"" + argument.getName() + "\""); } } else if (argument.isInput() && argument.isOutput()) { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<group>\n" + " <port name=\"" + argument.getName() + "in" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"input\"/>\n" + " </port>\n" + " <port name=\"" + argument.getName() + "out" + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + " <property name=\"output\"/>\n" + " </port>\n" + "</group>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct " + "input or output " + "port for argument \"" + argument.getName() + "\""); } } else { try { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\">\n" + (argument.isInput() ? " <property name=\"input\"/>\n" : "") + (argument.isOutput() ? " <property name=\"output\"/>\n" : "") + "</port>"); request.setUndoable(true); requestChange(request); } catch (Exception ex) { throw new IllegalActionException( this, ex, "Unable to construct " + "port for argument \"" + argument.getName() + "\""); } } } else { // synchronized the arguments and the ports if (argument.isReturn()) { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\"\n" + " <property name=\"output\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } else { MoMLChangeRequest request = new MoMLChangeRequest( this, this, "<port name=\"" + argument.getName() + "\" class=\"ptolemy.actor.TypedIOPort\"\n" + " <property name=\"input\"/>\n" + "</port>"); request.setUndoable(true); requestChange(request); } } port = (TypedIOPort) this.getPort(argument.getName()); if (port != null) { port.setTypeEquals(BaseType.GENERAL); } } }
/** * 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(); } }
/** * React to a list of objects being dropped onto a target. * * @param target The target on which the objects are dropped. * @param dropObjects The list of objects dropped onto the target. * @param moml The moml string generated for the dropped objects. * @exception IllegalActionException If the handling is unsuccessful. */ public void dropObject(NamedObj target, List dropObjects, String moml) throws IllegalActionException { boolean merge = false; if (target instanceof State) { State state = (State) target; TreeMap<Class<? extends Entity>, String> map = _getRefinementClasses(); String refinementClass = null; boolean conflict = false; RefinementSuggestion suggestion = (RefinementSuggestion) target.getAttribute("refinementSuggestion"); for (Object dropObject : dropObjects) { if (suggestion != null) { String className = suggestion.getRefinementClass((NamedObj) dropObject); if (refinementClass == null) { refinementClass = className; } else if (!refinementClass.equals(className)) { conflict = true; } } else { for (Class<? extends Entity> keyClass : map.keySet()) { if (keyClass.isInstance(dropObject)) { String value = map.get(keyClass); if (refinementClass == null) { refinementClass = value; break; } else if (!refinementClass.equals(value)) { conflict = true; break; } } } } if (conflict) { break; } } if (conflict || refinementClass == null) { throw new IllegalActionException( this, "Unable to determine " + "the type of all the dropped objects."); } TypedActor[] refinements = state.getRefinement(); TypedActor refinement = null; if (refinements != null) { for (TypedActor actor : refinements) { if (((NamedObj) actor).getClassName().equals(refinementClass)) { refinement = actor; break; } } } if (refinement == null) { CompositeEntity containerContainer = (CompositeEntity) state.getContainer().getContainer(); String name = containerContainer.uniqueName(state.getName()); addRefinement(state, name, null, refinementClass, null); merge = true; refinement = (TypedActor) containerContainer.getEntity(name); } target = (NamedObj) refinement; } MoMLChangeRequest request = new MoMLChangeRequest(this, target, moml); request.setUndoable(true); if (merge) { request.setMergeWithPreviousUndo(true); } target.requestChange(request); }
/** * Queue a change request to alter the value of the attribute attached to the specified entry, if * there is one. This method is called whenever an entry has been changed. If no attribute is * attached to the specified entry, then do nothing. * * @param name The name of the entry that has changed. */ public void changed(final String name) { // Check if the entry that changed is in the mapping. if (_attributes.containsKey(name)) { final Settable attribute = (Settable) (_attributes.get(name)); if (attribute == null) { // No associated attribute. return; } ChangeRequest request; if (attribute instanceof PasswordAttribute) { // Passwords have to be handled specially because the password // is not represented in a string. request = new ChangeRequest(this, name) { protected void _execute() throws IllegalActionException { char[] password = getCharArrayValue(name); ((PasswordAttribute) attribute).setPassword(password); attribute.validate(); Iterator<?> derived = ((PasswordAttribute) attribute).getDerivedList().iterator(); while (derived.hasNext()) { PasswordAttribute derivedPassword = (PasswordAttribute) derived.next(); derivedPassword.setPassword(password); } } }; } else if (attribute instanceof NamedObj) { // NOTE: We must use a MoMLChangeRequest so that changes // propagate to any objects that have been instantiating // using this one as a class. This is only an issue if // attribute is a NamedObj. NamedObj castAttribute = (NamedObj) attribute; String stringValue = getStringValue(name); // If the attribute is a DoubleRangeParameter, then we // have to translate the integer value returned by the // JSlider into a double. if (attribute instanceof DoubleRangeParameter) { try { int newValue = Integer.parseInt(stringValue); int precision = ((IntToken) ((DoubleRangeParameter) attribute).precision.getToken()).intValue(); double max = ((DoubleToken) ((DoubleRangeParameter) attribute).max.getToken()).doubleValue(); double min = ((DoubleToken) ((DoubleRangeParameter) attribute).min.getToken()).doubleValue(); double newValueAsDouble = min + (((max - min) * newValue) / precision); stringValue = "" + newValueAsDouble; } catch (IllegalActionException e) { throw new InternalErrorException(e); } } // The context for the MoML should be the first container // above this attribute in the hierarchy that defers its // MoML definition, or the immediate parent if there is none. NamedObj parent = castAttribute.getContainer(); String moml = "<property name=\"" + castAttribute.getName() + "\" value=\"" + StringUtilities.escapeForXML(stringValue) + "\"/>"; request = new MoMLChangeRequest( this, // originator parent, // context moml, // MoML code null) { // base protected void _execute() throws Exception { synchronized (PtolemyQuery.this) { try { _ignoreChangeNotifications = true; super._execute(); } finally { _ignoreChangeNotifications = false; } } } }; } else { // If the attribute is not a NamedObj, then we // set its value directly. request = new ChangeRequest(this, name) { protected void _execute() throws IllegalActionException { attribute.setExpression(getStringValue(name)); attribute.validate(); /* NOTE: Earlier version: // Here, we need to handle instances of Variable // specially. This is too bad... if (attribute instanceof Variable) { // Will this ever happen? A // Variable that is not a NamedObj??? // Retrieve the token to force // evaluation, so as to check the // validity of the new value. ((Variable)attribute).getToken(); } */ } }; } // NOTE: This object is never removed as a listener from // the change request. This is OK because this query will // be closed at some point, and all references to it will // disappear, and thus both it and the change request should // become accessible to the garbage collector. However, I // don't quite trust Java to do this right, since it's not // completely clear that it releases resources when windows // are closed. It would be better if this listener were // a weak reference. // NOTE: This appears to be unnecessary, since we register // as a change listener on the handler. This results in // two notifications. EAL 9/15/02. request.addChangeListener(this); if (_handler == null) { request.execute(); } else { if (request instanceof MoMLChangeRequest) { ((MoMLChangeRequest) request).setUndoable(true); } // Remove the error handler so that this class handles // the error through the notification. Save the previous // error handler to restore after this request has been // processes. _savedErrorHandler = MoMLParser.getErrorHandler(); MoMLParser.setErrorHandler(null); _handler.requestChange(request); } } }