Search in sources :

Example 91 with IWorkbench

use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.

the class TextSearchVisitor method evalNonFileBufferDocuments.

/**
 * Returns a map from IFile to IDocument for all open, dirty editors. After creation this map
 * is not modified, so returning a non-synchronized map is ok.
 *
 * @return a map from IFile to IDocument for all open, dirty editors
 */
private Map<IFile, IDocument> evalNonFileBufferDocuments() {
    Map<IFile, IDocument> result = new HashMap<>();
    IWorkbench workbench = SearchPlugin.getDefault().getWorkbench();
    IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
    for (IWorkbenchWindow window : windows) {
        IWorkbenchPage[] pages = window.getPages();
        for (IWorkbenchPage page : pages) {
            IEditorReference[] editorRefs = page.getEditorReferences();
            for (IEditorReference editorRef : editorRefs) {
                IEditorPart ep = editorRef.getEditor(false);
                if (ep instanceof ITextEditor && ep.isDirty()) {
                    // only dirty editors
                    evaluateTextEditor(result, ep);
                }
            }
        }
    }
    return result;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) HashMap(java.util.HashMap) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IDocument(org.eclipse.jface.text.IDocument)

Example 92 with IWorkbench

use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.

the class SegmentedModeTest method testSegmentation.

/*
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=70934
	 */
@Test
public void testSegmentation() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart part = IDE.openEditor(page, fFile);
        try {
            if (part instanceof ITextEditor) {
                ITextEditor editor = (ITextEditor) part;
                editor.showHighlightRangeOnly(true);
                editor.setHighlightRange(5, 0, true);
                Control control = part.getAdapter(Control.class);
                if (control instanceof StyledText) {
                    StyledText styledText = (StyledText) control;
                    int caret = styledText.getCaretOffset();
                    styledText.replaceTextRange(caret, 0, "really ");
                    StringBuffer buffer = new StringBuffer(getOriginalContent());
                    buffer.insert(5, "really ");
                    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                    assertEquals(buffer.toString(), document.get());
                }
            }
        } finally {
            page.saveEditor(part, false);
        }
    } catch (PartInitException e) {
        assertTrue(false);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 93 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class CloseWelcomePageRule method before.

@Override
protected void before() {
    Display.getDefault().syncExec(() -> {
        final IWorkbench workbench = PlatformUI.getWorkbench();
        if (workbench.getIntroManager().getIntro() != null) {
            workbench.getIntroManager().closeIntro(workbench.getIntroManager().getIntro());
        }
        try {
            workbench.showPerspective(defaultPerspectiveId, workbench.getActiveWorkbenchWindow());
        } catch (WorkbenchException e) {
            e.printStackTrace();
        }
    });
    // $NON-NLS-1$
    final String PREF_ENABLE_LAUNCHBAR = "enableLaunchBar";
    // $NON-NLS-1$
    final String PREF_ENABLE_TARGETSELECTOR = "enableTargetSelector";
    // $NON-NLS-1$
    final String PREF_ENABLE_BUILDBUTTON = "enableBuildButton";
    Display.getDefault().asyncExec(() -> {
        final IPreferenceStore store = org.eclipse.launchbar.ui.controls.internal.Activator.getDefault().getPreferenceStore();
        store.setValue(PREF_ENABLE_LAUNCHBAR, false);
        store.setValue(PREF_ENABLE_TARGETSELECTOR, false);
        store.setValue(PREF_ENABLE_BUILDBUTTON, false);
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) WorkbenchException(org.eclipse.ui.WorkbenchException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 94 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class SystemTapRegexGenerator method generateFromPrintf.

/**
 * Generate a list of regular expressions that will capture the output of a given .stp script.
 * Only output coming from <code>printf</code> statements will be captured.
 * @param scriptPath The absolute path of the script to capture the output of.
 * @param maxToFind The maximum number of regexs to create and return.
 * A negative value indicates no limit.
 * @return A list of generated regexs, each paired with the number of capturing groups it has.
 */
public static List<Entry<String, Integer>> generateFromPrintf(IPath scriptPath, int maxToFind) {
    List<Entry<String, Integer>> regexs = new ArrayList<>();
    if (maxToFind == 0) {
        return regexs;
    }
    String contents = null;
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IEditorPart editor = ResourceUtil.findEditor(workbench.getActiveWorkbenchWindow().getActivePage(), root.getFile(scriptPath.makeRelativeTo(root.getLocation())));
    if (editor != null) {
        // If editor of this file is open, take current file contents.
        ITextEditor tEditor = editor.getAdapter(ITextEditor.class);
        IDocument document = tEditor.getDocumentProvider().getDocument(tEditor.getEditorInput());
        contents = CommentRemover.exec(document.get());
    } else {
        // If chosen file is not being edited or is outside of the workspace, use the saved contents of the file itself.
        contents = CommentRemover.execWithFile(scriptPath.toString());
    }
    // Now actually search the contents for "printf(...)" statements. (^|[\s({;])printf\("(.+?)",.+\)
    // $NON-NLS-1$
    Pattern pattern = Pattern.compile("(?<=[^\\w])printf\\(\"(.+?)\",.+?\\)");
    Matcher matcher = pattern.matcher(contents);
    while (matcher.find() && (maxToFind < 0 || regexs.size() < maxToFind)) {
        String regex = null;
        // Note: allow optional "long" modifier 'l'. Not captured because it doesn't impact output format.
        // Also, don't support variable width/precision modifiers (*).
        // TODO: Consider %m & %M support.
        // $NON-NLS-1$
        Pattern format = Pattern.compile("%([-\\+ \\#0])?(\\d+)?(\\.\\d*)?l?([bcdiopsuxX%])");
        // Only capture until newlines to preserve the "column" format.
        // Don't try gluing together output from multiple printfs
        // since asynchronous prints would make things messy.
        // $NON-NLS-1$
        String[] printls = matcher.group(1).split("\\\\n");
        for (int i = 0; i < printls.length; i++) {
            String printl = printls[i];
            // Ignore newlines if they are escaped ("\\n").
            if (printl.endsWith("\\")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                printls[i + 1] = printl.concat("\\n" + printls[i + 1]);
                continue;
            }
            Matcher fmatch = format.matcher(printl);
            int lastend = 0;
            int numColumns = 0;
            while (fmatch.find()) {
                numColumns++;
                char chr = fmatch.group(4) == null ? '\0' : fmatch.group(4).charAt(0);
                if (chr == '\0') {
                    // Skip this statement if an invalid regex is found.
                    regex = null;
                    break;
                }
                char flag = fmatch.group(1) == null ? '\0' : fmatch.group(1).charAt(0);
                int width = fmatch.group(2) == null ? 0 : Integer.parseInt(fmatch.group(2));
                String precision = fmatch.group(3) == null ? null : fmatch.group(3).substring(1);
                // First, add any non-capturing characters.
                String pre = addRegexEscapes(printl.substring(lastend, fmatch.start()));
                regex = lastend > 0 ? regex.concat(pre) : pre;
                lastend = fmatch.end();
                // Now add what will be captured.
                // $NON-NLS-1$
                String target = "(";
                if (chr == 'u' || (flag != '#' && chr == 'o')) {
                    // $NON-NLS-1$
                    target = target.concat("\\d+");
                } else if (chr == 'd' || chr == 'i') {
                    if (flag == '+') {
                        // $NON-NLS-1$
                        target = target.concat("\\+|");
                    } else if (flag == ' ') {
                        // $NON-NLS-1$
                        target = target.concat(" |");
                    }
                    // $NON-NLS-1$
                    target = target.concat("-?\\d+");
                } else if (flag == '#' && chr == 'o') {
                    // $NON-NLS-1$
                    target = target.concat("0\\d+");
                } else if (chr == 'p') {
                    // $NON-NLS-1$
                    target = target.concat("0x[a-f0-9]+");
                } else if (chr == 'x') {
                    if (flag == '#') {
                        // $NON-NLS-1$
                        target = target.concat("0x");
                    }
                    // $NON-NLS-1$
                    target = target.concat("[a-f0-9]+");
                } else if (chr == 'X') {
                    if (flag == '#') {
                        // $NON-NLS-1$
                        target = target.concat("0X");
                    }
                    // $NON-NLS-1$
                    target = target.concat("[A-F0-9]+");
                } else if (chr == 'b') {
                    // $NON-NLS-1$
                    target = target.concat(".");
                } else if (chr == 'c') {
                    if (flag != '#') {
                        // $NON-NLS-1$
                        target = target.concat(".");
                    } else {
                        // $NON-NLS-1$
                        target = target.concat("\\([a-z]|[0-9]{3})|.|\\\\");
                    }
                } else if (chr == 's') {
                    if (precision != null) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        target = target.concat(".{" + precision + "}");
                    } else {
                        // $NON-NLS-1$
                        target = target.concat(".+");
                    }
                } else {
                    // Invalid or unhandled format specifier. Skip this regex.
                    regex = null;
                    break;
                }
                // $NON-NLS-1$
                target = target.concat(")");
                // Ignore it for %b, which uses the width value in a different way.
                if (chr != 'b' && --width > 0) {
                    if (flag == '-') {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        target = target.concat(" {0," + width + "}");
                    } else if (flag != '0' || chr == 's' || chr == 'c') {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        target = " {0," + width + "}".concat(target);
                    }
                }
                regex = regex.concat(target);
            }
            if (regex != null) {
                // Finally, add the uncaptured remainder of the print statement to the regex.
                regexs.add(new SimpleEntry<>(regex.concat(addRegexEscapes(printl.substring(lastend))), numColumns));
            }
        }
    }
    return regexs;
}
Also used : Pattern(java.util.regex.Pattern) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IDocument(org.eclipse.jface.text.IDocument)

Example 95 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class SystemTapScriptGraphOptionsTab method createGraphCreateArea.

private void createGraphCreateArea(Composite comp) {
    comp.setLayout(new GridLayout(2, false));
    graphsTable = new Table(comp, SWT.SINGLE | SWT.BORDER);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    graphsTable.setLayoutData(layoutData);
    // Button to add another graph
    Composite buttonComposite = new Composite(comp, SWT.NONE);
    buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    buttonComposite.setLayout(gridLayout);
    // Button to add a new graph
    addGraphButton = new Button(buttonComposite, SWT.PUSH);
    addGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_AddGraphButton);
    addGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_AddGraphButtonToolTip);
    addGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Button to copy an existing graph
    duplicateGraphButton = new Button(buttonComposite, SWT.PUSH);
    duplicateGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_DuplicateGraphButton);
    duplicateGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_DuplicateGraphButtonToolTip);
    duplicateGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Button to edit an existing graph
    editGraphButton = new Button(buttonComposite, SWT.PUSH);
    editGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_EditGraphButton);
    editGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_EditGraphButtonToolTip);
    editGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Button to remove the selected graph/filter
    removeGraphButton = new Button(buttonComposite, SWT.PUSH);
    removeGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButton);
    removeGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButtonToolTip);
    removeGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Action to notify the buttons when to enable/disable themselves based
    // on list selection
    graphsTable.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        selectedTableItem = (TableItem) e.item;
        setSelectionControlsEnabled(true);
    }));
    // Brings up a new dialog box when user clicks the add button. Allows
    // selecting a new graph to display.
    addGraphButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        SelectGraphAndSeriesWizard wizard = new SelectGraphAndSeriesWizard(getCurrentDataset(), null);
        IWorkbench workbench = PlatformUI.getWorkbench();
        wizard.init(workbench, null);
        WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
        dialog.create();
        dialog.open();
        GraphData gd = wizard.getGraphData();
        if (gd != null) {
            TableItem item = new TableItem(graphsTable, SWT.NONE);
            graphsData.add(gd);
            setUpGraphTableItem(item, gd, false);
            updateLaunchConfigurationDialog();
        }
    }));
    // Adds a new entry to the list of graphs that is a copy of the one selected.
    duplicateGraphButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        GraphData gd = ((GraphData) selectedTableItem.getData()).getCopy();
        TableItem item = new TableItem(graphsTable, SWT.NONE);
        graphsData.add(gd);
        if (badGraphs.contains(selectedTableItem.getData())) {
            badGraphs.add(gd);
            setUpGraphTableItem(item, gd, true);
        } else {
            setUpGraphTableItem(item, gd, false);
        }
        updateLaunchConfigurationDialog();
    }));
    // When button is clicked, brings up same wizard as the one for adding
    // a graph. Data in the wizard is filled out to match the properties
    // of the selected graph.
    editGraphButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        SelectGraphAndSeriesWizard wizard = new SelectGraphAndSeriesWizard(getCurrentDataset(), (GraphData) selectedTableItem.getData());
        IWorkbench workbench = PlatformUI.getWorkbench();
        wizard.init(workbench, null);
        WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
        dialog.create();
        dialog.open();
        GraphData gd = wizard.getGraphData();
        if (gd == null) {
            return;
        }
        GraphData old_gd = (GraphData) selectedTableItem.getData();
        if (!gd.isCopyOf(old_gd)) {
            badGraphs.remove(old_gd);
            setUpGraphTableItem(selectedTableItem, gd, false);
            graphsData.set(graphsTable.indexOf(selectedTableItem), gd);
            checkErrors(selectedRegex);
            updateLaunchConfigurationDialog();
        }
    }));
    // Removes the selected graph/filter from the table
    removeGraphButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        GraphData gd = (GraphData) selectedTableItem.getData();
        graphsData.remove(gd);
        badGraphs.remove(gd);
        selectedTableItem.dispose();
        setSelectionControlsEnabled(false);
        checkErrors(selectedRegex);
        updateLaunchConfigurationDialog();
    }));
}
Also used : RowDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.row.RowDataSet) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) Table(org.eclipse.swt.widgets.Table) Stack(java.util.Stack) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ExceptionErrorDialog(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog) Matcher(java.util.regex.Matcher) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab) GraphFactory(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.GraphFactory) IDEPlugin(org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin) DataSetFactory(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.dataset.DataSetFactory) IPath(org.eclipse.core.runtime.IPath) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) GraphData(org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData) AbstractUIPlugin(org.eclipse.ui.plugin.AbstractUIPlugin) GridData(org.eclipse.swt.layout.GridData) LinkedList(java.util.LinkedList) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) PatternSyntaxException(java.util.regex.PatternSyntaxException) IDataSetParser(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSetParser) Combo(org.eclipse.swt.widgets.Combo) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) IDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSet) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Group(org.eclipse.swt.widgets.Group) SelectGraphAndSeriesWizard(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.SelectGraphAndSeriesWizard) IFilteredDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet) List(java.util.List) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) IWorkbench(org.eclipse.ui.IWorkbench) Pattern(java.util.regex.Pattern) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) LineParser(org.eclipse.linuxtools.systemtap.graphing.core.datasets.row.LineParser) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbench(org.eclipse.ui.IWorkbench) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) SelectGraphAndSeriesWizard(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.SelectGraphAndSeriesWizard) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) TableItem(org.eclipse.swt.widgets.TableItem) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) GraphData(org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData)

Aggregations

IWorkbench (org.eclipse.ui.IWorkbench)105 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)32 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)31 IEditorPart (org.eclipse.ui.IEditorPart)21 PartInitException (org.eclipse.ui.PartInitException)20 WizardDialog (org.eclipse.jface.wizard.WizardDialog)15 CoreException (org.eclipse.core.runtime.CoreException)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Shell (org.eclipse.swt.widgets.Shell)11 IResource (org.eclipse.core.resources.IResource)9 ISelection (org.eclipse.jface.viewers.ISelection)9 Display (org.eclipse.swt.widgets.Display)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)7 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 IProject (org.eclipse.core.resources.IProject)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)5