Java 类org.eclipse.emf.ecore.presentation.EcoreEditorPlugin 实例源码

项目:emf.utils    文件:ReadOnlyEcoreEditor.java   
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.create();
    saveAsDialog.setMessage(EcoreEditorPlugin.INSTANCE.getString("_UI_SaveAs_message"));
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            ResourceSet resourceSet = editingDomain.getResourceSet();
            Resource currentResource = resourceSet.getResources().get(0);
            URI newURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);

            Resource newResource = resourceSet.createResource(newURI);
            newResource.getContents().addAll(EcoreUtil.copyAll(currentResource.getContents()));
            resourceSet.getResources().remove(0);
            resourceSet.getResources().move(0, newResource);

            IFileEditorInput modelFile = new FileEditorInput(file);
            setInputWithNotify(modelFile);
            setPartName(file.getName());
            doSave(getActionBars().getStatusLineManager().getProgressMonitor());
        }
    }
}
项目:mondo-hawk    文件:HawkResourceExeedCustomizer.java   
@Override
public void createPages(ExeedEditor editor, Composite container, AdapterFactory adapterFactory) {
    /*
     * This is a slightly customized version of {@link EcoreEditor#createPages()}. The problem with
     * Ecore'hawkState version is that its DiagnosticDecorator implementation will scan the tree from leaves
     * to roots, propagating error markers. We need to disable this behaviour to be able to provide
     * "lazy" loading, and we have no place to do it but right where the DiagnosticDecorator instance
     * is created, as the setInput(...) call will start the redecoration process.
     */
    editor.setShowAllResources(true);

    // Creates the model from the editor input
    editor.createModelGen();

    // Only creates the other pages if there is something that can be edited
    //
    final EditingDomain editingDomain = editor.getEditingDomain();
    if (!editingDomain.getResourceSet().getResources().isEmpty())
    {
      // Create a page for the selection tree view.
      //
      Tree tree = new Tree(container, SWT.MULTI);
      TreeViewer selectionViewer = new TreeViewer(tree);
      editor.setCurrentViewer(selectionViewer);

      selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
      final IDialogSettings dialogSettings = EcoreEditorPlugin.getPlugin().getDialogSettings();
      final DiagnosticDecorator labelDecorator = new SingleNodeDiagnosticDecorator(editingDomain, selectionViewer, dialogSettings);
      selectionViewer.setLabelProvider(new DecoratingColumLabelProvider(new AdapterFactoryLabelProvider(adapterFactory), labelDecorator));
      selectionViewer.setInput(editingDomain.getResourceSet());
      selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);

      new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
      new ColumnViewerInformationControlToolTipSupport(selectionViewer, new DiagnosticDecorator.EditingDomainLocationListener(editingDomain, selectionViewer));

      editor.createContextMenuFor(selectionViewer);
      int pageIndex = editor.addPage(tree);
      editor.setPageText(pageIndex, EcoreEditorPlugin.INSTANCE.getString("_UI_SelectionPage_label"));
    }

    final IWorkbenchPage page = editor.getEditorSite().getPage();
    page.addPartListener(new UnloadResourceSetOnCloseListener(page, editor));
}
项目:NeoEMF    文件:NeoEditor.java   
@Override
    public void createPages()
    {
        Instant begin = Instant.now();
        createModel();

        // Only creates the other pages if there is something that can be edited
        if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
            // Create a page for the selection tree view.
            Tree tree = new Tree(getContainer(), SWT.VIRTUAL | SWT.FULL_SELECTION);
//          Tree tree = new Tree(getContainer(), SWT.VIRTUAL | SWT.MULTI);
            selectionViewer = new TreeViewer(tree);
            setCurrentViewer(selectionViewer);

//          selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setContentProvider(new LazyAdapterFactoryContentProvider(adapterFactory));
//          selectionViewer.setLabelProvider(new DecoratingColumLabelProvider(new AdapterFactoryLabelProvider(adapterFactory), new DiagnosticDecorator(editingDomain, selectionViewer, EcoreEditorPlugin.getPlugin().getDialogSettings())));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setUseHashlookup(true);
            selectionViewer.setInput(editingDomain.getResourceSet());
//          selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);

//          new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
//          new ColumnViewerInformationControlToolTipSupport(selectionViewer, new DiagnosticDecorator.EditingDomainLocationListener(editingDomain, selectionViewer));

            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(tree);
            setPageText(pageIndex, EcoreEditorPlugin.INSTANCE.getString("_UI_SelectionPage_label"));

            getSite().getShell().getDisplay().asyncExec(() -> setActivePage(0));
        }

        // Ensures that this editor will only display the page's tab area if there are more than one page
        getContainer().addControlListener(new ControlAdapter() {
            boolean guard = false;

            @Override
            public void controlResized(ControlEvent event) {
                if (!guard) {
                    guard = true;
                    hideTabs();
                    guard = false;
                }
            }
        });

        getSite().getShell().getDisplay().asyncExec(this::updateProblemIndication);

        Instant end = Instant.now();

        NeoLogger.info("NeoEMF Editor Opened in {0}", Duration.between(begin, end));
    }