Java Code Examples for org.eclipse.ui.IWorkbenchPartSite.getShell()

The following are Jave code examples for showing how to use getShell() of the org.eclipse.ui.IWorkbenchPartSite class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dsl-devkit   File: FixedHighlightingReconciler.java   View Source Code Vote up 6 votes
private Display getDisplay() {
  XtextEditor editor = this.editor;
  if (editor == null) {
    return null;
  }

  IWorkbenchPartSite site = editor.getSite();
  if (site == null) {
    return null;
  }

  Shell shell = site.getShell();
  if (shell == null || shell.isDisposed()) {
    return null;
  }

  Display display = shell.getDisplay();
  if (display == null || display.isDisposed()) {
    return null;
  }
  return display;
}
 
Example 2
Project: bts   File: HighlightingReconciler.java   View Source Code Vote up 6 votes
private Display getDisplay() {
	XtextEditor editor = this.editor;
	if (editor == null){
		if(sourceViewer != null)
			return sourceViewer.getControl().getDisplay();
		return null;
	}
	IWorkbenchPartSite site = editor.getSite();
	if (site == null)
		return null;

	Shell shell = site.getShell();
	if (shell == null || shell.isDisposed())
		return null;

	Display display = shell.getDisplay();
	if (display == null || display.isDisposed())
		return null;
	return display;
}
 
Example 3
Project: Eclipse-Postfix-Code-Completion   File: SemanticHighlightingReconciler.java   View Source Code Vote up 6 votes
/**
 * Update the presentation.
 *
 * @param textPresentation the text presentation
 * @param addedPositions the added positions
 * @param removedPositions the removed positions
 */
private void updatePresentation(TextPresentation textPresentation, List<Position> addedPositions, List<Position> removedPositions) {
	Runnable runnable= fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
	if (runnable == null)
		return;

	JavaEditor editor= fEditor;
	if (editor == null)
		return;

	IWorkbenchPartSite site= editor.getSite();
	if (site == null)
		return;

	Shell shell= site.getShell();
	if (shell == null || shell.isDisposed())
		return;

	Display display= shell.getDisplay();
	if (display == null || display.isDisposed())
		return;

	display.asyncExec(runnable);
}
 
Example 4
Project: Eclipse-Postfix-Code-Completion-Juno38   File: SemanticHighlightingReconciler.java   View Source Code Vote up 6 votes
/**
 * Update the presentation.
 *
 * @param textPresentation the text presentation
 * @param addedPositions the added positions
 * @param removedPositions the removed positions
 */
private void updatePresentation(TextPresentation textPresentation, List<Position> addedPositions, List<Position> removedPositions) {
	Runnable runnable= fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
	if (runnable == null)
		return;

	JavaEditor editor= fEditor;
	if (editor == null)
		return;

	IWorkbenchPartSite site= editor.getSite();
	if (site == null)
		return;

	Shell shell= site.getShell();
	if (shell == null || shell.isDisposed())
		return;

	Display display= shell.getDisplay();
	if (display == null || display.isDisposed())
		return;

	display.asyncExec(runnable);
}
 
Example 5
Project: Notepad4e   File: Note.java   View Source Code Vote up 5 votes
/**
 * Exports the brute text in the current note as a text file.
 * 
 * @param iWorkbenchPartSite
 */
public void exportToFile(IWorkbenchPartSite iWorkbenchPartSite) {
	// Retrieve the file to save to with an explorer window.
	FileDialog fileDialog = new FileDialog(iWorkbenchPartSite.getShell(), SWT.SAVE);
	fileDialog.setText(LocalStrings.dialogExportTitle);
	String fileName = fileDialog.open();
	// Invalid name specified.
	if (fileName == null || fileName.isEmpty()) {
		return;
	}

	File file = new File(fileName);
	if (file.exists() && !MessageDialog.openQuestion(iWorkbenchPartSite.getShell(),
			LocalStrings.dialogOverwriteTitle, LocalStrings.dialogOverwriteMsg)) {
		return;
	}

	// Write the current note's text to the file, with handling of IO exceptions.
	try (FileOutputStream outStream = new FileOutputStream(file);
			PrintWriter printStream = new PrintWriter(outStream)) {
		printStream.print(getText());
		printStream.flush();
		MessageDialog.openInformation(iWorkbenchPartSite.getShell(), LocalStrings.dialogExportedTitle,
				LocalStrings.dialogExportedMsg);
	} catch (IOException e) {
		MessageDialog.openInformation(iWorkbenchPartSite.getShell(), LocalStrings.dialogErrorTitle,
				LocalStrings.dialogErrorMsg);
		Notepad4e.getDefault().getLog().log(new Status(IStatus.ERROR, LocalStrings.dialogErrorMsg, e.toString()));
	}
}
 
Example 6
Project: Eclipse-Postfix-Code-Completion   File: ClipboardOperationAction.java   View Source Code Vote up 5 votes
private Shell getShell() {
	ITextEditor editor= getTextEditor();
	if (editor != null) {
		IWorkbenchPartSite site= editor.getSite();
		Shell shell= site.getShell();
		if (shell != null && !shell.isDisposed()) {
			return shell;
		}
	}
	return null;
}
 
Example 7
Project: Eclipse-Postfix-Code-Completion-Juno38   File: ClipboardOperationAction.java   View Source Code Vote up 5 votes
private Shell getShell() {
	ITextEditor editor= getTextEditor();
	if (editor != null) {
		IWorkbenchPartSite site= editor.getSite();
		Shell shell= site.getShell();
		if (shell != null && !shell.isDisposed()) {
			return shell;
		}
	}
	return null;
}
 
Example 8
Project: textuml   File: SourceEditor.java   View Source Code Vote up 5 votes
public void format() {
    Display display = null;
    IWorkbenchPartSite site = getSite();
    Shell shell = site.getShell();
    if (shell != null && !shell.isDisposed())
        display = shell.getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {
        public void run() {
            doFormat();
        }
    });
}
 
Example 9
Project: org.csstudio.display.builder   File: ContextMenuSupport.java   View Source Code Vote up 4 votes
/** Create SWT context menu
 *  @param site RCP site
 *  @param parent Parent SWT widget
 *  @param representation Representation
 */
public ContextMenuSupport(final RuntimeViewPart view, final Control parent, final RCP_JFXRepresentation representation)
{
    this.view = view;
    final IWorkbenchPartSite site = view.getSite();
    shell = site.getShell();

    // Tried to use a JFX context menu on the individual items,
    // but adding the existing PV contributions requires parsing
    // the registry and creating suitable JFX menu entries.
    // Finally, it was unclear how to set the "activeMenuSelection"
    // required by existing object contributions.
    //
    // So using SWT context menu, automatically populated with PV contributions.

    // Selection provider to inform RCP about PV for the context menu
    final ISelectionProvider sel_provider = new RCPSelectionProvider();
    site.setSelectionProvider(sel_provider);

    // RCP context menu w/ "additions" placeholder for contributions
    final MenuManager mm = new MenuManager();
    mm.setRemoveAllWhenShown(true);
    mm.addMenuListener(manager -> fillContextMenu(manager));
    site.registerContextMenu(mm, sel_provider);

    // Create menu ..
    final Menu menu = mm.createContextMenu(parent);
    // .. but _don't_ attach to SWT control
    //     parent.setMenu(menu);

    // Menu is shown by representation listener _after_
    // setting the selection to widget's PV
    final ToolkitListener tkl = new ToolkitListener()
    {
        @Override
        public void handleContextMenu(final Widget widget)
        {
            IStructuredSelection sel = StructuredSelection.EMPTY;
            final Optional<WidgetProperty<String>> name_prop = widget.checkProperty(propPVName);
            if (name_prop.isPresent())
            {
                final String pv_name = name_prop.get().getValue();
                if (!pv_name.isEmpty())
                    sel = new StructuredSelection(new ProcessVariable(pv_name));
            }
            sel_provider.setSelection(sel);

            // Show the menu
            view.setActiveWidget(widget);
            menu.setVisible(true);
        }
    };
    representation.addListener(tkl);
    parent.addDisposeListener(event -> representation.removeListener(tkl));
}
 
Example 10
Project: Eclipse-Postfix-Code-Completion   File: JarPackageActionDelegate.java   View Source Code Vote up 4 votes
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	IWorkbenchPartSite site= targetPart.getSite();
	fShell= site != null ? site.getShell() : null;
}
 
Example 11
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JarPackageActionDelegate.java   View Source Code Vote up 4 votes
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	IWorkbenchPartSite site= targetPart.getSite();
	fShell= site != null ? site.getShell() : null;
}