Search in sources :

Example 61 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.

the class TestCSSContentAssistComputers method testAdditionalProposalInfo.

public void testAdditionalProposalInfo() throws Exception {
    IFile file = getFile("test4.css");
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineLength(7) + 23;
    ICompletionProposal[][] pages = getProposals(viewer, offset, 4);
    assertTrue("Not enough pages", pages.length > 0);
    ICompletionProposal[] proposals = pages[0];
    for (int i = 0; i < proposals.length; i++) {
        if (proposals[i] instanceof ICompletionProposalExtension5) {
            Object obj = ((ICompletionProposalExtension5) proposals[i]).getAdditionalProposalInfo(null);
            assertTrue("Additional info must be of type ProposalInfo", obj instanceof ProposalInfo);
            ProposalInfo info = (ProposalInfo) obj;
            assertNotNull("CSSMMNode for Proposal Info should not be null", info);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposalExtension5(org.eclipse.jface.text.contentassist.ICompletionProposalExtension5) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 62 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.

the class ViewerTestDTD method addActions.

protected void addActions(IContributionManager mgr) {
    if (mgr != null) {
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "New HTML";
            }

            public void run() {
                super.run();
                BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {

                    public void run() {
                        setupViewerForNew();
                        fSourceViewer.setEditable(true);
                    }
                });
            }
        });
        mgr.add(new Separator());
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Change Visibility";
            }

            public void run() {
                super.run();
                NumberInputDialog dlg = new NumberInputDialog(fSourceViewer.getControl().getShell());
                int proceed = dlg.open();
                if (proceed == Window.CANCEL)
                    return;
                fSourceViewer.resetVisibleRegion();
                fSourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Show All";
            }

            public void run() {
                super.run();
                fSourceViewer.resetVisibleRegion();
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Change Visibility in Editor";
            }

            public void run() {
                super.run();
                StructuredTextViewer sourceViewer = null;
                IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
                if (part != null && part instanceof StructuredTextEditor) {
                    sourceViewer = ((StructuredTextEditor) part).getTextViewer();
                }
                if (sourceViewer != null) {
                    NumberInputDialog dlg = new NumberInputDialog(sourceViewer.getControl().getShell());
                    int proceed = dlg.open();
                    if (proceed == Window.CANCEL)
                        return;
                    sourceViewer.resetVisibleRegion();
                    sourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
                }
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Show All in Editor";
            }

            public void run() {
                super.run();
                StructuredTextViewer sourceViewer = null;
                IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
                if (part != null && part instanceof StructuredTextEditor) {
                    sourceViewer = ((StructuredTextEditor) part).getTextViewer();
                }
                if (sourceViewer != null) {
                    sourceViewer.resetVisibleRegion();
                }
            }
        });
        mgr.add(new Separator());
        // no longer able to set fInput to NULL
        // mgr.add(new Action() {
        // public String getText() {
        // return getToolTipText();
        // }
        // 
        // public String getToolTipText() {
        // return "Set Input to NULL";
        // }
        // public void run() {
        // super.run();
        // viewer.setInput(null);
        // }
        // });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input from Active Editor";
            }

            public void run() {
                super.run();
                ITextEditor textEditor = getActiveEditor();
                if (textEditor != null) {
                    setupViewerForEditor(textEditor);
                    fSourceViewer.setEditable(true);
                }
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input and Follow Selection";
            }

            public void run() {
                super.run();
                followSelection();
                fSourceViewer.setEditable(true);
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input and Follow Selection As ReadOnly";
            }

            public void run() {
                super.run();
                followSelection();
                fSourceViewer.setEditable(false);
            }
        });
        mgr.add(new Action() {

            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Stop Following Selection";
            }

            public void run() {
                super.run();
                stopFollowSelection();
            }
        });
    }
}
Also used : Action(org.eclipse.jface.action.Action) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) Separator(org.eclipse.jface.action.Separator)

Example 63 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project liferay-ide by liferay.

the class WorkflowDefinitionEditor method _saveWorkflowDefinitionEntry.

private void _saveWorkflowDefinitionEntry(WorkflowDefinitionEditorInput definitionInput) {
    StructuredTextEditor sourceEditor = getXmlEditor();
    WorkflowDefinitionEntry definition = definitionInput.getWorkflowDefinitionEntry();
    String titleMap = definition.getTitleMap();
    String titleCurrentValue = definition.getTitleCurrentValue();
    IDocumentProvider documentProvider = sourceEditor.getDocumentProvider();
    IDocument document = documentProvider.getDocument(getEditorInput());
    String definitionContent = document.get();
    String[] newTitleMap = new String[1];
    if ((titleCurrentValue != null) && (titleMap != null)) {
        try {
            String localeCode = Locale.getDefault().toString();
            JSONObject jsonTitleMap = new JSONObject(titleMap);
            Iterator<?> keys = jsonTitleMap.keys();
            while ((keys != null) && keys.hasNext()) {
                Object key = keys.next();
                String value = jsonTitleMap.getString(key.toString());
                if ((value != null) && value.contains(titleCurrentValue)) {
                    localeCode = key.toString();
                    break;
                }
            }
            jsonTitleMap.put(localeCode, titleCurrentValue);
            newTitleMap[0] = jsonTitleMap.toString();
        } catch (Exception e) {
        }
    } else {
        newTitleMap[0] = definition.getTitleMap();
    }
    if (empty(newTitleMap[0])) {
        try {
            newTitleMap[0] = KaleoUtil.createJSONTitleMap(definition.getTitle());
        } catch (JSONException jsone) {
        }
    }
    int draftVersion = definition.getDraftVersion() + 1;
    if (draftVersion == 0) {
        draftVersion = 1;
    }
    int newDraftVersion = draftVersion;
    Job saveWorkflowEntry = new Job("Saving kaleo workflow entry.") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus retval = Status.OK_STATUS;
            try {
                JSONObject updatedDraftDefinition = null;
                IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(definition.getParent().getParent());
                try {
                    JSONObject latestDraftDefinition = kaleoConnection.getLatestKaleoDraftDefinition(definition.getName(), definition.getVersion(), definition.getCompanyId());
                    if (latestDraftDefinition != null) {
                        updatedDraftDefinition = kaleoConnection.updateKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, latestDraftDefinition.getInt("version"), latestDraftDefinition.getInt("draftVersion"), definition.getCompanyId(), definition.getUserId());
                    } else {
                        updatedDraftDefinition = kaleoConnection.addKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, definition.getVersion(), newDraftVersion, definition.getUserId(), definition.getGroupId());
                    }
                } catch (Exception e) {
                    updatedDraftDefinition = kaleoConnection.addKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, definition.getVersion(), newDraftVersion, definition.getUserId(), definition.getGroupId());
                }
                WorkflowDefinitionEntry newNode = WorkflowDefinitionEntry.createFromJsObject(updatedDraftDefinition);
                newNode.setParent(definition.getParent());
                newNode.setCompanyId(definition.getCompanyId());
                newNode.setContent(definitionContent);
                newNode.setDraftVersion(newDraftVersion);
                newNode.setName(definition.getName());
                newNode.setLocation(definition.getLocation());
                newNode.setTitleCurrentValue(titleCurrentValue);
                newNode.setTitleMap(newTitleMap[0]);
                newNode.setUserId(definition.getUserId());
                newNode.setVersion(definition.getVersion());
                newNode.setGroupId(definition.getGroupId());
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        IEditorInput editInput = getEditorInput();
                        WorkflowDefinitionEditorInput workflowEditorInput = (WorkflowDefinitionEditorInput) editInput;
                        workflowEditorInput.setWorkflowDefinitionEntry(newNode);
                        setPartName(workflowEditorInput.getName());
                        firePropertyChange(propUpdateVersion);
                    }
                });
            } catch (Exception e) {
                retval = KaleoUI.createErrorStatus("Could not save kaleo workflow entry.", e);
            }
            return retval;
        }
    };
    saveWorkflowEntry.schedule();
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IStatus(org.eclipse.core.runtime.IStatus) JSONException(org.json.JSONException) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Job(org.eclipse.core.runtime.jobs.Job) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 64 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project syncope by apache.

the class TemplateEditor method createPage.

void createPage(final String inputString, final String title, final String tooltip) {
    try {
        if (title.equals(SyncopeView.TEMPLATE_FORMAT_HTML)) {
            editor = new HTMLEditor();
        } else {
            editor = new StructuredTextEditor();
        }
        int index = addPage(editor, (IEditorInput) new TemplateEditorInput(inputString, title, tooltip));
        setPageText(index, editor.getTitle());
    } catch (final PartInitException e) {
        ErrorDialog.openError(getSite().getShell(), ERROR_NESTED_EDITOR, null, e.getStatus());
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 65 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    textEditor = new StructuredTextEditor() {

        @Override
        public boolean isEditable() {
            return false;
        }

        @Override
        public boolean isEditorInputModifiable() {
            return false;
        }

        @Override
        public boolean isEditorInputReadOnly() {
            return true;
        }

        @Override
        public boolean isDirty() {
            return false;
        }
    };
    textEditor.setEditorPart(this);
    if (input instanceof FileEditorInput) {
        setInput(input);
        IFile file = ((FileEditorInput) input).getFile();
        WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(file.getProject());
        // force initialization
        project.getDesignerProxy();
        WorkflowPackage pkg = project.getPackage((IFolder) file.getParent());
        taskTemplate = (TaskTemplate) pkg.getTaskTemplate(file);
        // refresh from file system to make sure we're in sync
        try {
            Long taskId = taskTemplate.getId();
            int version = taskTemplate.getVersion();
            file.refreshLocal(IResource.DEPTH_ZERO, null);
            String content = new String(PluginUtil.readFile(file));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.parse(content);
                com.centurylink.mdw.task.TaskTemplate fileTemplate = doc.getTaskTemplate();
                taskVO = new TaskVO(fileTemplate);
            }
            taskTemplate.setTaskVO(taskVO);
            taskVO.setName(file.getName());
            taskVO.setTaskId(taskId);
            taskTemplate.setId(taskId);
            taskTemplate.setVersion(version);
            taskVO.setPackageName(pkg.getName());
        } catch (Exception ex) {
            throw new PartInitException(ex.getMessage(), ex);
        }
    } else {
        throw new PartInitException("Invalid input: " + input);
    }
    selectionProvider = new WorkflowSelectionProvider(taskTemplate);
    site.setSelectionProvider(selectionProvider);
    setPartName(taskTemplate.getName());
    addPageChangedListener(new IPageChangedListener() {

        public void pageChanged(PageChangedEvent event) {
            if (getSelectedPage() == pages.get("Variables")) {
                reconcileVariables();
            }
        }
    });
    partListener = new IPartListener2() {

        public void partOpened(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partActivated(IWorkbenchPartReference partRef) {
            IWorkbenchPart part = partRef.getPart(false);
            if (part == TaskTemplateEditor.this && getSelectedPage() == pages.get("Variables"))
                reconcileVariables();
        }

        public void partBroughtToTop(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partDeactivated(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partClosed(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partVisible(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partHidden(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partInputChanged(IWorkbenchPartReference partRef) {
        // do nothing
        }
    };
    getSite().getPage().addPartListener(partListener);
    workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            return MdwPlugin.getActivePage().closeEditor(TaskTemplateEditor.this, true);
        }

        public void postShutdown(IWorkbench workbench) {
        // do nothing
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) IFile(org.eclipse.core.resources.IFile) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) WorkflowSelectionProvider(com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException) IPartListener2(org.eclipse.ui.IPartListener2) IWorkbench(org.eclipse.ui.IWorkbench) JSONObject(org.json.JSONObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Aggregations

StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)67 IFile (org.eclipse.core.resources.IFile)29 IEditorPart (org.eclipse.ui.IEditorPart)28 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)18 IDocument (org.eclipse.jface.text.IDocument)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 Position (org.eclipse.jface.text.Position)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BadLocationException (org.eclipse.jface.text.BadLocationException)9 ITextSelection (org.eclipse.jface.text.ITextSelection)6 PartInitException (org.eclipse.ui.PartInitException)6 XMLMultiPageEditorPart (org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Action (org.eclipse.jface.action.Action)4 Separator (org.eclipse.jface.action.Separator)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3