Examples of DeviceRepositoryAccessorManager


Examples of com.volantis.mcs.eclipse.ab.core.DeviceRepositoryAccessorManager

        container.setLayout(gridLayout);

        try {
            // get the file for the repository that is in the same jar as
            // this class
            repositoryManager = new DeviceRepositoryAccessorManager(
                    deviceRepositoryFile.getPath(), new JAXPTransformerMetaFactory(),
                    new DefaultJDOMFactory(), false);

            // create the StructurePolicyValueModifier
            StructurePolicyValueModifier modifier =
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

    // rest of javadoc inherited
    public Object getAdapter(Class adapterClass) {
        Object adapter = null;
        if (DeviceRepositoryBrowserPage.class.equals(adapterClass)) {
            IProject project = context.getPolicyResource().getProject();
            DeviceRepositoryAccessorManager dram = null;
            try {
                // When the DeviceRepositoryBrowser is opened use a new
                // dram rather than from the ProjectDeviceRepositoryProvider
                // just in case there have already been unsaved changes to
                // the dram in the ProjectDeviceRepositoryProvider that would
                // be picked up here. I.e. the browser should only see changes
                // to the device repository when there is a save or the
                // property is changed. This is done with the
                // ProjectDeviceRepositoryChangeListener below.
                dram = new DeviceRepositoryAccessorManager(MCSProjectNature.
                        getDeviceRepositoryName(project),
                        new JAXPTransformerMetaFactory(),
                        new DefaultJDOMFactory(), false);

                final DeviceRepositoryBrowserPage page =
                        new DeviceRepositoryBrowserPage(dram);
                projDeviceRepositoryChangeListener =
                        new ProjectDeviceRepositoryChangeListener() {
                            public void changed() {
                                try {
                                    DeviceRepositoryAccessorManager dram =
                                            ProjectDeviceRepositoryProvider.
                                            getSingleton().
                                            getDeviceRepositoryAccessorManager(
                                                    getFile().
                                            getProject());
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

                                           DeviceEditorContext context) {
        super(parent, style);

        setMinWidth(DEFAULT_MIN_WIDTH);
        this.context = context;
        DeviceRepositoryAccessorManager dram =
                context.getDeviceRepositoryAccessorManager();

        Section section =
                SectionFactory.createSection(this, SWT.NONE, TITLE, MESSAGE);
        GridData data = new GridData(GridData.FILL_BOTH);
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

        this.project = project;
        if (project == null || !project.exists()) {
            deviceTree.setInput(null);
        } else {
            try {
                DeviceRepositoryAccessorManager dram =
                        ProjectDeviceRepositoryProvider.getSingleton().
                        getDeviceRepositoryAccessorManager(project);
                deviceTree.setInput(dram.getDeviceHierarchyDocument().
                        getRootElement());
                deviceTree.refresh();
            } catch (RepositoryException re) {
                EclipseCommonPlugin.logError(BuilderPlugin.getDefault(),
                        getClass(), re);
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

        this.project = project;
        if (project == null || !project.exists()) {
            deviceList.setInput(null);
        } else {
            try {
                DeviceRepositoryAccessorManager dram =
                        ProjectDeviceRepositoryProvider.getSingleton().
                        getDeviceRepositoryAccessorManager(project);
                deviceList.setInput(dram.getDeviceHierarchyDocument().
                        getRootElement());
                deviceList.refresh();
            } catch (RepositoryException re) {
                EclipseCommonPlugin.logError(BuilderPlugin.getDefault(),
                        getClass(), re);
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

    private void initializeViewerContent() {
        if (!viewerInitialized) {
            // Provide data for the viewer.
            checkboxTreeViewer.setContentProvider(contentProvider);
            try {
                DeviceRepositoryAccessorManager dram =
                        ProjectDeviceRepositoryProvider.getSingleton().
                        getDeviceRepositoryAccessorManager(project);
                checkboxTreeViewer.setInput(dram.getDeviceHierarchyDocument().
                        getRootElement());
                viewerInitialized = true;
            } catch (RepositoryException e) {
                EclipseCommonPlugin.handleError(BuilderPlugin.getDefault(), e);
            }
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

     * Show an empty list message if the list/tree is empty.
     */
    private void showEmptyListMessage(Label label, Button button) {
        if (project != null) {
            try {
                DeviceRepositoryAccessorManager dram =
                        ProjectDeviceRepositoryProvider.getSingleton().
                        getDeviceRepositoryAccessorManager(project);
                if (!contentProvider.
                        hasChildren(dram.getDeviceHierarchyDocument().
                        getRootElement())) {
                    setErrorMessage(ThemesMessages.getString(RESOURCE_PREFIX +
                            "emptyList"));
                    button.setEnabled(false);
                    label.setEnabled(false);
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

        // Assume that the IEditorInput is a file i.e the device repository file
        IFile file = getFile(editorInput);

        try {
            String fileName = file.getLocation().toOSString();
            dram = new DeviceRepositoryAccessorManager(fileName,
                    new JAXPTransformerMetaFactory(),
                    new DefaultJDOMFactory(), false);
        } catch (IOException e) {
            // PartInitExceptions are not logged by Eclipse so throw an
            // UndeclaredThrowable...
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

            // is disposed if the user closes the view and if re-opened
            // must be recreated. There is no dispose listener interface
            // for view parts.
            DeviceEditorContext context =
                    (DeviceEditorContext) getODOMEditorContext();
            DeviceRepositoryAccessorManager dram =
                    context.getDeviceRepositoryAccessorManager();
            // create the OutlinePage
            ODOMOutlinePage outlinePage = new ODOMOutlinePage(
                    getODOMEditorContext(),
                    (ODOMElement) dram.getDeviceHierarchyDocument().
                            getRootElement(),
                    deviceFilter,
                    null, // no skip elements
                    null, // no stop elements
                    false, // attributes are not children
View Full Code Here

Examples of com.volantis.mcs.eclipse.core.DeviceRepositoryAccessorManager

        viewDeviceXMLAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "viewDevice.") {

            protected void runImpl() {
            DeviceRepositoryAccessorManager dram =
                    context.getDeviceRepositoryAccessorManager();
            String selectedDeviceName = getDeviceName(getSelectedDevice());
                XMLWindow window = new XMLWindow(getShell(),
                        dram.retrieveDeviceElement(selectedDeviceName),
                        selectedDeviceName + ".xml");
                window.open();
            }
        };

        // create the view identification xml action
        viewIdentificationXMLAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "viewIdentification.") {

            protected void runImpl() {
            DeviceRepositoryAccessorManager dram =
                    context.getDeviceRepositoryAccessorManager();
                XMLWindow window = new XMLWindow(getShell(),
                        dram.getDeviceIdentificationDocument().
                        getRootElement(), "identification.xml");
                window.open();
            }
        };


        // create the view definitions xml action
        viewDefinitionsXMLAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "viewDefinitions.") {

            protected void runImpl() {
            DeviceRepositoryAccessorManager dram =
                    context.getDeviceRepositoryAccessorManager();
                XMLWindow window = new XMLWindow(getShell(),
                        dram.getDeviceDefinitionsDocument().
                        getRootElement(), "definitions.xml (combined)");
                window.open();
            }
        };

        // create the view definitions xml action
        viewTACXMLAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "viewTAC.") {

            protected void runImpl() {
            DeviceRepositoryAccessorManager dram =
                    context.getDeviceRepositoryAccessorManager();
                XMLWindow window = new XMLWindow(getShell(),
                        dram.getDeviceTACIdentificationDocument().
                        getRootElement(), "tac.xml");
                window.open();
            }
        };

        // create the new action
        newAction = context.new DemarcatingResourceAction(
                DevicesMessages.getResourceBundle(),
                RESOURCE_PREFIX + "new.") {
            // javadoc inherited
            protected void runImpl() {
                final DeviceRepositoryAccessorManager dram = context.
                        getDeviceRepositoryAccessorManager();
                NewDeviceWizard wizard = new NewDeviceWizard(
                        getShell(),
                        CONTENT_PROVIDER,
                        treeViewer.getSelection(),
                        dram.getDeviceHierarchyDocument().getRootElement(),
                        context);

                int result = wizard.open();
                if (result == Window.OK) {
                    String fallbackDevice = wizard.getFallbackDevice();
                    String newDeviceName = wizard.getDevice();

                    if ((fallbackDevice != null) && (newDeviceName != null)) {
                        try {
                            // Create the new device element.
                            dram.createDevice(fallbackDevice, newDeviceName);

                            // Create the XPath for selecting the new device
                            // element just created from the hierarchy
                            // document.
                            final StringBuffer newDeviceXPathBuffer =
                                    new StringBuffer();
                            newDeviceXPathBuffer.append("//").
                                    append(MCSNamespace.DEVICE_HIERARCHY.
                                    getPrefix()).
                                    append(':').
                                    append(DeviceRepositorySchemaConstants.
                                    DEVICE_ELEMENT_NAME).
                                    append("[@").
                                    append(DeviceRepositorySchemaConstants.
                                    DEVICE_NAME_ATTRIBUTE).
                                    append("=\"").append(newDeviceName).
                                    append("\"]");
                            final XPath newDeviceXPath =
                                    new XPath(newDeviceXPathBuffer.toString(),
                                            new Namespace[]{MCSNamespace.
                                    DEVICE_HIERARCHY});

                            Element newDeviceElement = null;
                            try {
                                // Get the hierarchy root for the XPath search.
                                final Element hierarchyRoot = dram.
                                        getDeviceHierarchyDocument().
                                        getRootElement();

                                // Retrieve the new device element.
                                newDeviceElement = newDeviceXPath.
                                        selectSingleElement(hierarchyRoot);
                            } catch (XPathException e) {
                                EclipseCommonPlugin.
                                        handleError(ABPlugin.getDefault(), e);
                            }

                            // Expand the tree to the new device element's level
                            // and select it.
                            treeViewer.expandToLevel(newDeviceElement, 1);
                            treeViewer.setSelection(
                                    new StructuredSelection(newDeviceElement),
                                    true);
                        } catch (RepositoryException e) {
                            EclipseCommonPlugin.handleError(ABPlugin.getDefault(),
                                    e);
                            throw new UndeclaredThrowableException(e);
                        }
                    }
                }
            }
        };

        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(),
                        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
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.