Examples of UndoRedoManager


Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        String[] patterns = new String[items.length];
        for (int i = 0; i < items.length; i++) {
            patterns[i] = (String) items[i];
        }

        UndoRedoManager undoRedoManager = context.getUndoRedoManager();
        undoRedoManager.demarcateUOW();

        selectedDeviceIdentification.removeChangeListener(odomChangeListener);
        try {
            context.getDeviceRepositoryAccessorManager().setUserAgentPatterns(
                    getSelectedDeviceName(), patterns);
        } catch (RepositoryException e) {
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
        } finally {
            selectedDeviceIdentification.addChangeListener(odomChangeListener);
            undoRedoManager.demarcateUOW();
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

            IActionBars editorSiteActionBars = this.getEditorSite().
                    getActionBars();

            if (editorSiteActionBars != null) {
                UndoRedoManager undoRedoManager = context.getUndoRedoManager();
                ODOMEditorContribution.assignUndoRedoAction(editorSiteActionBars,
                        undoRedoManager, IWorkbenchActionConstants.UNDO);

                ODOMEditorContribution.assignUndoRedoAction(editorSiteActionBars,
                        undoRedoManager, IWorkbenchActionConstants.REDO);
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        // The editor has changed so we need to swap the UndoRedoManager instance
        // with the current global UNDO/REDO actions.
        if (currentEditor != null) {
            ODOMEditorContext odomEditorContext = currentEditor.getODOMEditorContext();
            UndoRedoManager newManager = odomEditorContext.getUndoRedoManager();
            IActionBars actionBars = odomEditorContext.getActionBars();

            // Ensure that the current action for UNDO/REDO has been created
            // and assigned to the global action handler. Thus ensuring
            // only one UNDO and one REDO action is created.
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

                DeviceRepositoryAccessorManager dram =
                        context.getDeviceRepositoryAccessorManager();
                String newName = getNewName(oldName, dram, false);
                if (newName != null) {
                    UndoRedoManager undoRedoManager =
                            context.getUndoRedoManager();
                    try {
                        // we don't allow device renames to be undoable
                        undoRedoManager.enable(false);
                        dram.renameDevice(oldName, newName);
                    } catch (RepositoryException re) {
                        EclipseCommonPlugin.handleError(ABPlugin.getDefault(),
                                re);
                        throw new UndeclaredThrowableException(re);
                    } finally {
                        // re-enable the undo manager
                        undoRedoManager.enable(true);
                    }
                }
            }

            /**
             * Prompts for a new name for the device.
             *
             * @param oldName The old name of the device
             * @param dram The device repository accessor manager for the device
             *             repository being edited
             * @param hasAdminRights True if the user has admin rights, false
             *                       otherwise
             * @return The new name for the device, or null if the request was
             *         cancelled.
             */
            private String getNewName(final String oldName,
                                   final DeviceRepositoryAccessorManager dram,
                                   final boolean hasAdminRights) {
                final RE deviceNameMatch =
                        new RE(DeviceConstants.DEVICE_NAME_REGEXP_STRING);
                IInputValidator validator = new IInputValidator() {
                    public String isValid(String string) {
                        if (!hasAdminRights && !string.startsWith("_")) {
                            string = "_" + string;
                        }

                        if (string == null || "".equals(string)) {
                            return RENAME_DEVICE_ERROR_EMPTY;
                        } else if (string.length() >
                                DeviceConstants.TEXT_MAX_LENGTH) {
                            return RENAME_DEVICE_ERROR_LENGTH;
                        } else if (oldName.equals(string)) {
                            return RENAME_DEVICE_ERROR_UNCHANGED;
                        } else if (dram.deviceExists(string)) {
                            return RENAME_DEVICE_ERROR_EXISTS;
                        } else if (deviceNameMatch.match(string)) {
                            if (deviceNameMatch.getParenLength(0) !=
                                    string.length()) {
                                return RENAME_DEVICE_ERROR_INVALID;
                            }
                        } else {
                            return RENAME_DEVICE_ERROR_INVALID;
                        }

                        return null;
                    }
                };

                InputDialog dialog = new InputDialog(getShell(),
                        RENAME_DEVICE_TITLE, RENAME_DEVICE_MESSAGE,
                        oldName, validator);
                dialog.setBlockOnOpen(true);
                int result = dialog.open();

                // Return the entered name if the dialog was completed
                // successfully.
                String newName = null;
                if (result == Dialog.OK) {
                    newName = dialog.getValue();
                    // Add a leading _ if necessary for non-admin users
                    if (!hasAdminRights && !newName.startsWith("_")) {
                        newName = "_" + newName;
                    }
                }
                return newName;
            }
        };

        // create the move action
        moveAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "move.") {
            // javadoc inherited
            protected void runImpl() {
                // get hold of the node that is to be moved
                final ODOMElement selected = getSelectedDevice();
                // create the dialog that allows the user to select the
                // destination for the "move" device action

                // we need to filter out the selected node from the
                // NodeSelectionDialog as it does not make sense to move the
                // selected device to itself or a descendent of itself.
                // We can do this by wrapping the hierarchy content provider
                // in a FilteringTreeContentProvider that filters out the
                // selected device.
                ITreeContentProvider filteringContentProvider =
                        new FilteringTreeContentProvider(
                                CONTENT_PROVIDER,
                                new FilteringTreeContentProvider.NodeFilter() {
                                    // To store the filtered nodes
                                    List filtered = new ArrayList();

                                    // javadoc inherited
                                    public Object[] filter(Object[] nodes) {
                                        filtered.clear();
                                        // filter out the selected device if
                                        // it is in the list of nodes
                                        for (int i = 0; i < nodes.length; i++) {
                                            if (nodes[i] != selected) {
                                                filtered.add(nodes[i]);
                                            }
                                        }
                                        return filtered.toArray();
                                    }
                                });
                // create the dialog that allows the user to select the new
                // position in the device hierarchy.
                NodeSelectionDialog dialog = new NodeSelectionDialog(
                        displayArea.getShell(),
                        SELECT_DEVICE_MESSAGE,
                        context.getDeviceRepositoryAccessorManager().
                        getDeviceHierarchyDocument().getRootElement(),
                        filteringContentProvider,
                        new DeviceHierarchyLabelProvider());

                // set the title for the dialog
                dialog.setTitle(SELECT_DEVICE_TITLE);
                // display the dialog
                dialog.open();
                // retrieve the selected device
                Object[] result = dialog.getResult();
                // if the result is null then the user pressed the cancel
                // button. However, if it is non null then a selection will
                // have been made and the result array should contain 1
                // ODOMElement - the device that was selected.
                if (result != null) {
                    // check that the result array contains a single ODOMElement
                    if (result.length != 1) {
                        throw new IllegalStateException(
                                "Expected a single device to be selected" +
                                " but got " + result.length);
                    }
                    // cast to an ODOMelement
                    ODOMElement parent = (ODOMElement) result[0];
                    // finally move the selected device to the new location
                    DeviceRepositoryAccessorManager dram =
                            context.getDeviceRepositoryAccessorManager();
                    try {
                        dram.moveDevice(getDeviceName(selected),
                                getDeviceName(parent));
                    } catch (RepositoryException e) {
                        EclipseCommonPlugin.handleError(ABPlugin.getDefault(),
                                e);
                        throw new UndeclaredThrowableException(e);
                    }
                    // ensure that device that has been moved is selected
                    treeViewer.setSelection(new StructuredSelection(selected));
                }
            }
        };

        // create the remove action
        deleteAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "delete.") {
            // javadoc inherited
            protected void runImpl() {
                // get hold of the selected device
                ODOMElement selected = getSelectedDevice();
                String message = MessageFormat.format(
                        DELETE_DEVICE_MESSAGE,
                        new String[]{getDeviceName(selected)});

                if (MessageDialog.openQuestion(getShell(),
                        DELETE_DEVICE_TITLE,
                        message)) {
                    DeviceRepositoryAccessorManager dram =
                            context.getDeviceRepositoryAccessorManager();
                    UndoRedoManager undoRedoManager =
                            context.getUndoRedoManager();
                    try {
                        // we don't allow device deletions to be undoable
                        undoRedoManager.enable(false);
                        dram.removeDevice(getDeviceName(selected));
                    } catch (RepositoryException e) {
                        EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
                    } finally {
                        // ensure the undo redo manager is enabled.
                        undoRedoManager.enable(true);
                    }

                }
            }
        };
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

                    "undoRedoMementoOriginator cannot be null"); //$NON-NLS-1$
        }

        this.oDOMSelectionManager = createODOMSelectionManager();

        this.undoRedoManager = new UndoRedoManager(undoRedoMementoOriginator);

        if (rootElement != null) {
            addRootElement(rootElement, rootElementIdentifier);
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        DeviceHeaderPattern[] patterns = new DeviceHeaderPattern[items.length];
        for (int i = 0; i < items.length; i++) {
            patterns[i] = (DeviceHeaderPattern) items[i];
        }

        UndoRedoManager undoRedoManager = context.getUndoRedoManager();
        undoRedoManager.demarcateUOW();

        selectedDeviceIdentification.removeChangeListener(odomChangeListener);
        try {
            context.getDeviceRepositoryAccessorManager().
                    setHeaderPatterns(getSelectedDeviceName(), patterns);

        } catch (RepositoryException e) {
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
        } finally {
            selectedDeviceIdentification.addChangeListener(odomChangeListener);
            undoRedoManager.demarcateUOW();
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        DeviceODOMElement currentPolicy =
                (DeviceODOMElement) context.
                getDeviceRepositoryAccessorManager().
                retrievePolicy(deviceName, policyName);

        UndoRedoManager undoRedoManager = context.getUndoRedoManager();
        undoRedoManager.demarcateUOW();
        try {
            // It may be the case that the user has chosen to override when
            // override was previously selected in which case the resolved policy
            // will come from the current device and we must do some special
            // processing to handle the standard element that should be present
            if (currentPolicy != null) {
                currentPolicy.override((DeviceODOMElement) policy);
            } else {
                // This is an override. Where there is no existing policy so nothing to
                // remove, only something to add.
                policies.addContent(policy);
            }
        } finally {
            undoRedoManager.demarcateUOW();
        }
        // Enable the controls to allow the user to modify the override value.
        enableModifierControls(true);

        modifier.setPolicy(policy);
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        // Retrieve the current policy.
        ODOMElement policy = (ODOMElement)
                context.getDeviceRepositoryAccessorManager().
                resolvePolicy(deviceName, policyName).policy;

        UndoRedoManager undoRedoManager = context.getUndoRedoManager();
        undoRedoManager.demarcateUOW();
        try {
            // Remove all value or field content from the policy.
            if (policy.getAttributeValue(
                    DeviceRepositorySchemaConstants.
                    POLICY_VALUE_ATTRIBUTE) != null) {
                policy.removeAttribute(
                        DeviceRepositorySchemaConstants.POLICY_VALUE_ATTRIBUTE);
            } else {

                // Remove all value element children, if any.
                policy.removeChildren(DeviceRepositorySchemaConstants.
                        POLICY_VALUE_ELEMENT_NAME, policy.getNamespace());

                // Remove all field element children, if any.
                policy.removeChildren(DeviceRepositorySchemaConstants.
                        POLICY_DEFINITION_FIELD_ELEMENT_NAME,
                        policy.getNamespace());
            }

            // Create and add the inherit element
            Element inherit =
                    ODOM_FACTORY.element(DeviceRepositorySchemaConstants.
                    INHERIT_ELEMENT_NAME, policy.getNamespace());

            // Adding the inherit element as the first element child node ensures
            // that it precedes any standard element, as this must come last
            // according to the schema.
            List children = policy.getChildren();
            children.add(0, inherit);

            // Retrieve the fallback policy and give it to the PolicyValueModifier.
            Element fallbackPolicy =
                    context.getDeviceRepositoryAccessorManager().
                    resolvePolicy(deviceName, policyName).policy;
            modifier.setPolicy(fallbackPolicy);

            // Disable the PolicyValueModifier controls since the device now
            // inherits the value rather than providing it directly.
            enableModifierControls(false);
        } finally {
            undoRedoManager.demarcateUOW();
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

    private void handleRestoreSelection() {
        Element policy = context.getDeviceRepositoryAccessorManager().
                retrievePolicy(deviceName, policyName);
        if (policy != null) {

            UndoRedoManager undoRedoManager = context.getUndoRedoManager();
            undoRedoManager.demarcateUOW();
            try {
                // If we are here then there is something to restore.
                ((DeviceODOMElement) policy).restore();

                // We need to do the resolve again in case the restore
                // has changed it.
                policy = context.getDeviceRepositoryAccessorManager().
                        resolvePolicy(deviceName, policyName).policy;

                modifier.setPolicy(policy);
            } finally {
                undoRedoManager.demarcateUOW();
            }
        }
        updateOriginSelector();
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.undo.UndoRedoManager

        String[] patterns = new String[items.length];
        for (int i = 0; i < items.length; i++) {
            patterns[i] = (String) items[i];
        }

        UndoRedoManager undoRedoManager = context.getUndoRedoManager();
        undoRedoManager.demarcateUOW();

        selectedDeviceIdentification.removeChangeListener(odomChangeListener);
        try {
            context.getDeviceRepositoryAccessorManager().setDeviceTACs(
                    getSelectedDeviceName(), patterns);
        } catch (RepositoryException e) {
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
        } finally {
            selectedDeviceIdentification.addChangeListener(odomChangeListener);
            undoRedoManager.demarcateUOW();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.