Examples of ODOMElement


Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

     * Delete simply removes all selected elements from the document.
     * <p>
     * To support undo/redo children nodes are deleted before parents.
     */
    public void run(ODOMActionDetails details) {
        ODOMElement element;
        Element parent;

        // javadoc for details.getElements() tells us we get a clone,
        // so we can sort that array directly
        ODOMElement[] detailsElementsClone = details.getElementsClone();
        sortChildrenFirst(detailsElementsClone);

        for (int i = 0;
             i < detailsElementsClone.length;
             i++) {
            element = detailsElementsClone[i];
            parent = element.getParent();

            // Delete can be used to delete formats or device layouts, but
            // the processing is different in these two cases
            if (parent.getParent() != null) {
                // Only non-empty formats need to be handled (deletion of
                // an empty format does nothing)
                if (!element.getName().equals(
                        FormatType.EMPTY.getElementName())) {
                    // A format is being deleted as opposed to a device
                    // layout so an empty format must take its place
                    List content = parent.getContent();
                    int index = content.indexOf(element);

                    // This automatically detaches the original element
                    content.set(index, FormatPrototype.get(FormatType.EMPTY));
                }
            } else if (parent != null) {
                // Simply remove the device layout
                element.detach();
            }
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

    // javadoc inherited
    public void dragSetData(DragSourceEvent event) {
        // Provide the data of the requested type.
        if (transfer.isSupportedType(event.dataType)) {
            ODOMElement elements [] = actionDetails.getElementsClone();
            event.data = elements;
        }
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

            if (variantTypeProxy != null) {
                variantTypeProxy.addListener(typeChangeListener, false);
            }

            try {
                final ODOMElement rootElement =
                    odomEditorContext.getRootElement();
                if (rootElement != null) {
                    odomEditorContext.removeRootElement(rootElement);
                }

                // Check whether the variant is null;
                boolean isNullVariant = false;
                if (variantTypeProxy != null) {
                    isNullVariant =  (VariantType.NULL ==
                            variantTypeProxy.getModelObject());
                }

                ODOMElement newRootElement = null;

                if (isNullVariant) {
                    // Pretend we've got no selection so that we display that
                    // there is no content to edit.
                    odomEditorContext.getODOMSelectionManager().setSelection(
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

     */
    private ODOMElement getRootElementForVariant(
            final BeanProxy variantBuilderProxy, final IFile file)
        throws IOException, CoreException, JDOMException {

        ODOMElement root = (ODOMElement)
            variantBuilderProxyToRootElement.get(variantBuilderProxy);
        if (root == null) {
            root = ODOMEditorUtils.createRootElement(file,
                ODOMEditorContext.ODOM_FACTORY);
            // Add the schema location for the LPDM schema.
            Namespace xsiNamespace =
                    Namespace.getNamespace("xsi",
                            W3CSchemata.XSI_NAMESPACE);
            root.setAttribute("schemaLocation",
                    PolicySchemas.MARLIN_LPDM_CURRENT.getNamespaceURL() +
                    " " + PolicySchemas.MARLIN_LPDM_CURRENT.getLocationURL(),
                    xsiNamespace);
            variantBuilderProxyToRootElement.put(variantBuilderProxy, root);
            final ODOMElement odomContentRoot = root;
            root.addChangeListener(new ODOMChangeListener() {
                public void changed(ODOMObservable node, ODOMChangeEvent event) {
                    odomNodeChanged(variantBuilderProxy, odomContentRoot);
                }
            });
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

                            variantBuilderProxy.getPropertyProxy(PolicyModel.CONTENT);
                        if (VariantType.NULL == variantBuilderProxy.getPropertyProxy(
                                PolicyModel.VARIANT_TYPE).getModelObject()) {
                            contentBuilderProxy.setModelObject(null);
                        } else if (!contentBuilderProxy.isReadOnly()) {
                            final ODOMElement element = (ODOMElement) entry.getValue();
                            final ContentBuilder contentBuilder = documentToBuilder(
                                    element.getDocument(), contentBuilderProxy);
                            contentBuilderProxy.setModelObject(contentBuilder);
                        }
                    }
                } catch (IOException e) {
                    throw new PolicyFileAccessException(e);
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

        String masterDeviceName = context.
            getDeviceRepositoryAccessorManager().retrieveRootDeviceName();

        policyController.setDeviceName(masterDeviceName);

        ODOMElement masterElement =
            (ODOMElement) context.getDeviceRepositoryAccessorManager().
                retrieveDeviceElement(masterDeviceName);

        // Add the master element as a root of the context, this is so
        // that if the user changes the master value the device document
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

        Document hierarchyDocument =
                context.getDeviceRepositoryAccessorManager().
                getDeviceHierarchyDocument();

        try {
            ODOMElement hierarchyRootElement =
                    (ODOMElement) hierarchyDocument.getRootElement();

            context.addRootElement(hierarchyRootElement,
                    DeviceRepositorySchemaConstants.HIERARCHY_ELEMENT_NAME);

            MarkerGeneratingErrorReporter errorReporter =
                    context.getErrorReporter(hierarchyRootElement);

            LocationDetailsRegistry registry =
                    errorReporter.getLocationDetailsRegistry();
            if (registry == null) {
                registry = new LocationDetailsRegistry();
                errorReporter.setLocationDetailsRegistry(registry);
            }

            DefaultJDOMFactory factory = new DefaultJDOMFactory();

            Element element = factory.element(DeviceRepositorySchemaConstants.
                    DEVICE_ELEMENT_NAME,
                    MCSNamespace.DEVICE_HIERARCHY);

            LocationDetails details =
                    new DeviceLocationDetails(ERROR_LOCATION_FORMAT,
                            MCSNamespace.DEVICE_HIERARCHY);

            registry.registerLocationDetails(element, details);
        } catch (SAXException e) {
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
        } catch (ParserErrorException e) {
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
        }

        // create this sections display area
        createDisplayArea(TITLE, MESSAGE);

        final ODOMSelectionManager selectionManager =
                context.getODOMSelectionManager();

        // create a listener that responds to ODOMElement selections
        ODOMElementSelectionListener deviceSelectionListener =
                new ODOMElementSelectionListener() {
                    // javadoc inherited
                    public void selectionChanged(
                            ODOMElementSelectionEvent event) {
                        treeViewer.removeSelectionChangedListener(
                                selectionManager);
                        treeViewer.setSelection(event.getSelection(), true);
                        treeViewer.getTree().showSelection();
                        treeViewer.addSelectionChangedListener(
                                selectionManager);

                        ODOMElement selected = getSelectedDevice();
                        boolean enable = (selected != null &&
                                !isRootDevice(selected) &&
                                (context.isAdminProject() ||
                                !context.getDeviceRepositoryAccessorManager().
                                isStandardDevice(getDeviceName(selected))));
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

        renameAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "rename.") {
            // javadoc inherited
            protected void runImpl() {
                final ODOMElement selected = getSelectedDevice();
                String oldName = getDeviceName(selected);

                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(),
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

        sourceTargetPairs.clear();

        // Loop through the event elements (if any)
        final Iterator sourceElementsIter = event.getSelection().iterator();
        while (sourceElementsIter.hasNext()) {
            final ODOMElement sourceElement =
                (ODOMElement) sourceElementsIter.next();

            // Add the source/target pair, where the target is navigated to
            // from the source using sourceToTargetPath (which may be null,
            // but that is handled OK by navigateToTarget)
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMElement

            ignoreChangeEvents = true;

            // Just loop through all the non-null targets, changing their name
            boolean targetsUpdated = false;
            for (int i = 0; i < sourceTargetPairs.size(); i++) {
                final ODOMElement target = sourceTargetPairs.getTarget(i);
               
                // TODO Should we create a target if we find a null one
                // (which could only be the case if target was a (grand)
                // child of source) - if so set targetsUpdated = true;
                if (target != null) {
                    target.setName(name);
                    targetsUpdated = true;
                }
            }

            // If the targets have been updated, we need to tell both the
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.