Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.ChangeRequest


    /** Insert a feedback loop.
     */
    public void insertFeedback() {
        // Create an anonymous inner class
        ChangeRequest change = new ChangeRequest(this, "test2") {
            protected void _execute() throws Exception {
                _const.output.unlinkAll();
                _rec.input.unlinkAll();

                AddSubtract add = new AddSubtract(_top, "add");
View Full Code Here


    }

    /** Create a change request that always throws an exception. */
    public ChangeRequest mutateBadChangeRequest() {
        // Create an anonymous inner class
        changeRequest = new ChangeRequest(this,
                "Change request that always throws an Exception") {
            protected void _execute() throws Exception {
                if (1 == 1) {
                    throw new Exception("Always Thrown Exception");
                }
View Full Code Here

    }

    /** Create a change request that sets const to 2.0. */
    public ChangeRequest mutateConst2ChangeRequest() {
        // Create an anonymous inner class
        changeRequest = new ChangeRequest(this, "Changing Const to 2.0") {
            protected void _execute() throws Exception {
                _const.value.setToken(new DoubleToken(2.0));
            }
        };
        return changeRequest;
View Full Code Here

        ;

        String moml = getDeleteNodeMoML(node);

        // Note: The source is NOT the graph model.
        ChangeRequest request = new MoMLChangeRequest(this, container, moml);
        container.requestChange(request);
    }
View Full Code Here

    private void _setPortSignalTypes(final SignalTypeMap typeMap) {
        Director director = (Director) getContainer();
        final CompositeActor container = (CompositeActor) director
                .getContainer();

        ChangeRequest request = new ChangeRequest(this, "Record signal types") {
            protected void _execute() throws KernelException {
                Iterator entities = container.deepEntityList().iterator();

                while (entities.hasNext()) {
                    Entity entity = (Entity) entities.next();

                    for (Iterator ports = entity.portList().iterator(); ports
                            .hasNext();) {
                        IOPort port = (IOPort) ports.next();
                        String typeString = typeMap.getType(port).toString();
                        _setOrCreate(port, "resolvedSignalType", typeString);
                    }
                }
            }
        };

        // Indicate that the change is non-persistent, so that
        // the UI doesn't prompt to save.
        request.setPersistent(false);
        container.requestChange(request);
    }
View Full Code Here

                    // trigger a redraw of the entire graph, which will result
                    // in another call to this very same method, which will
                    // result in creation of yet another figure before this
                    // method even returns!
                    final EditorIcon finalIcon = icon;
                    ChangeRequest request = new ChangeRequest(_model,
                            "Set the container of a new XMLIcon.") {
                        // NOTE: The KernelException should not be thrown,
                        // but if it is, it will be handled properly.
                        protected void _execute() throws KernelException {
                            _iconsPendingContainer.remove(object);

                            // If the icon already has a container, do nothing.
                            if (finalIcon.getContainer() != null) {
                                return;
                            }

                            // If the container already has an icon, do nothing.
                            if (object.getAttribute("_icon") != null) {
                                return;
                            }

                            finalIcon.setContainer(object);
                        }
                    };

                    request.setPersistent(false);
                    object.requestChange(request);
                }
            } catch (KernelException ex) {
                throw new InternalErrorException("could not create icon "
                        + "in " + object + " even "
View Full Code Here

                                        getFrame(), target);

                    } else { //edit the existing attribute
                        final Attribute docAttribute = (Attribute) docAttributeList
                                .get(docAttributeList.size() - 1);
                        ChangeRequest request = new ChangeRequest(this,
                                "Customize documentation.") {
                            protected void _execute() throws Exception {
                                //_editDocAttribute(getFrame(), docAttribute, target);
                                docApplicationSpecializer.editDocumentation(
                                        getFrame(), docAttribute, target);
                            }
                        };
                        target.requestChange(request);
                    }
                } catch (Exception ee) {
                    System.out
                            .println("Failed to call doc application specializer "
                                    + "class \""
                                    + docApplicationSpecializerClassName
                                    + "\" on class \""
                                    + docApplicationSpecializerClassName
                                    + "\".");
                }
                done = true;
            }

            if (!done) {
                //assign the docAttributeList the default DocAttribute if it
                //wasn't assigned by the specializer
                docAttributeList = target.attributeList(DocAttribute.class);
                if (docAttributeList.size() == 0) {
                    // Create a doc attribute, then edit its parameters.
                    String moml = "<property name=\""
                            + "DocAttribute"
                            + "\" class=\"ptolemy.vergil.basic.DocAttribute\"/>";
                    MoMLChangeRequest request = new MoMLChangeRequest(this,
                            target, moml) {
                        protected void _execute() throws Exception {
                            super._execute();
                            List docAttributes = target
                                    .attributeList(DocAttribute.class);

                            // There shouldn't be more than one of
                            // these, but if there are, the new one is
                            // the last one.

                            DocAttribute attribute = (DocAttribute) docAttributes
                                    .get(docAttributes.size() - 1);
                            _editDocAttribute(getFrame(), attribute, target);
                        }
                    };
                    target.requestChange(request);
                } else {

                    // In case there is more than one such attribute,
                    // get the last one.

                    final DocAttribute attribute = (DocAttribute) docAttributeList
                            .get(docAttributeList.size() - 1);

                    // Do the update in a change request because it may
                    // modify the DocAttribute parameter.

                    ChangeRequest request = new ChangeRequest(this,
                            "Customize documentation.") {
                        protected void _execute() throws Exception {

                            // In case parameters or ports have been
                            // added since the DocAttribute was
View Full Code Here

                            "Invalid directorClass.");
                }

                // NOTE: Creating a new director has to be done in a
                // change request.
                ChangeRequest request = new ChangeRequest(this,
                        "Create a new director") {
                    protected void _execute() throws Exception {
                        Director director = getDirector();

                        // Contruct a new director
View Full Code Here

            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);
                }

View Full Code Here

                // and the model will just repeatedly pop up exception
                // windows, with no escape.
                if (_setFailed) {
                    return false;
                }
                ChangeRequest request = new ChangeRequest(this,
                        "SetVariable change request") {
                    protected void _execute() throws IllegalActionException {
                        _setValue(value);
                    }
                };

                // To prevent prompting for saving the model, mark this
                // change as non-persistent.
                request.setPersistent(false);
                request.addChangeListener(this);
                requestChange(request);
            } else {
                _setValue(value);
            }
            if (output.getWidth() > 0) {
View Full Code Here

TOP

Related Classes of ptolemy.kernel.util.ChangeRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.