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;
}
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);
}
}
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);
});
}
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;
}
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();
}));
}
Aggregations