Java Code Examples for org.eclipse.ui.IWorkbenchPartSite

The following are top voted examples for showing how to use org.eclipse.ui.IWorkbenchPartSite. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gw4e.project   File: JDTManager.java   View source code 6 votes vote down vote up
/**
 * @param project
 */
public static void reorganizeImport(final ICompilationUnit cu) {

	Display.getDefault().syncExec(() -> {
		try {
			IWorkbenchWindow iww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			if (iww == null)
				return;
			IPartService partService = iww.getPartService();
			if (partService == null)
				return;
			IWorkbenchPart wp = partService.getActivePart();
			if (wp == null)
				return;
			IWorkbenchPartSite targetSite = wp.getSite();
			if (targetSite == null)
				return;
			organizeImports(cu, targetSite);
		} catch (Exception e) {
			ResourceManager.logException(e);
		}
	});
}
 
Example 2
Project: google-cloud-eclipse   File: ServiceUtils.java   View source code 6 votes vote down vote up
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
Example 3
Project: dsl-devkit   File: FixedHighlightingReconciler.java   View source code 6 votes vote down vote up
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 4
Project: tlaplus   File: AbstractPDFViewerRunnable.java   View source code 6 votes vote down vote up
public AbstractPDFViewerRunnable(ProducePDFHandler handler, IWorkbenchPartSite site, IResource aSpecFile) {
	Assert.isNotNull(handler);
	Assert.isNotNull(site);
	Assert.isNotNull(aSpecFile);
	this.handler = handler;
	this.specFile = aSpecFile;
	
	final boolean autoRegenerate = TLA2TeXActivator.getDefault().getPreferenceStore()
			.getBoolean(ITLA2TeXPreferenceConstants.AUTO_REGENERATE);
	if (autoRegenerate) {
		// Subscribe to the event bus with which the TLA Editor save events are
		// distributed. In other words, every time the user saves a spec, we
		// receive an event and provided the spec corresponds to this PDF, we
		// regenerate it.
		// Don't subscribe in EmbeddedPDFViewerRunnable#though, because it is run
		// repeatedly and thus would cause us to subscribe multiple times.
		final IEventBroker eventService = site.getService(IEventBroker.class);
		Assert.isTrue(eventService.subscribe(TLAEditor.SAVE_EVENT, this));
		
		// Register for part close events to deregister the event handler
		// subscribed to the event bus. There is no point in regenerating
		// the PDF if no PDFEditor is open anymore.
		final IPartService partService = site.getService(IPartService.class);
		partService.addPartListener(this);
	}
}
 
Example 5
Project: bts   File: HighlightingReconciler.java   View source code 6 votes vote down vote up
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 6
Project: statecharts   File: RenameElementHandler.java   View source code 6 votes vote down vote up
@Override
public boolean isEnabled() {
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window == null) {
		return false;
	}
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	if (site == null) {
		return false;
	}
	ISelectionProvider selectionProvider = site.getSelectionProvider();
	if (selectionProvider == null) {
		return false;
	}
	ISelection currentSelection = selectionProvider.getSelection();
	setContext(refactoring, currentSelection);
	return refactoring.isExecutable();
}
 
Example 7
Project: PDFReporter-Studio   File: ASPropertyWidget.java   View source code 6 votes vote down vote up
private IStatusLineManager getStatusLineManager() {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

	IWorkbenchPage page = win.getActivePage();

	IWorkbenchPart part = page.getActivePart();
	if (part == null)
		return null;
	IWorkbenchPartSite site = part.getSite();
	IActionBars actionBars = null;
	if (site instanceof IEditorSite)
		actionBars = ((IEditorSite) site).getActionBars();
	else if (site instanceof IViewSite)
		actionBars = ((IViewSite) site).getActionBars();
	if (actionBars == null)
		return null;
	return actionBars.getStatusLineManager();
}
 
Example 8
Project: PDFReporter-Studio   File: MultiPageToolbarEditorPart.java   View source code 6 votes vote down vote up
/**
 * Disposes the given part and its site.
 * 
 * @param part
 *          The part to dispose; must not be <code>null</code>.
 */
private void disposePart(final IWorkbenchPart part) {
	SafeRunner.run(new ISafeRunnable() {
		public void run() {
			IWorkbenchPartSite partSite = part.getSite();
			part.dispose();
			if (partSite instanceof MultiPageToolbarEditorSite) {
				((MultiPageToolbarEditorSite) partSite).dispose();
			}
		}

		public void handleException(Throwable e) {
			// Exception has already being logged by Core. Do nothing.
		}
	});
}
 
Example 9
Project: PDFReporter-Studio   File: ADataInput.java   View source code 6 votes vote down vote up
private IStatusLineManager getStatusLineManager() {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

	IWorkbenchPage page = win.getActivePage();
	if (page == null)
		return null;
	IWorkbenchPart part = page.getActivePart();
	if (part == null)
		return null;
	IWorkbenchPartSite site = part.getSite();
	IActionBars actionBars = null;
	if (site instanceof IEditorSite)
		actionBars = ((IEditorSite) site).getActionBars();
	else if (site instanceof IViewSite)
		actionBars = ((IViewSite) site).getActionBars();
	if (actionBars == null)
		return null;

	return actionBars.getStatusLineManager();
}
 
Example 10
Project: PDFReporter-Studio   File: StyledTextXtextAdapter.java   View source code 6 votes vote down vote up
protected void initSelectionProvider() {
	// Overrides the editors selection provider to provide the text
	// selection if opened within an editor context
	try {
		IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor().getSite();
		XtextStyledTextSelectionProvider xtextStyledTextSelectionProvider = new XtextStyledTextSelectionProvider();
		ChangeSelectionProviderOnFocusGain listener = new ChangeSelectionProviderOnFocusGain(site,
				xtextStyledTextSelectionProvider);
		styledText.addFocusListener(listener);
		styledText.addDisposeListener(listener);
	} catch (NullPointerException ex) {
		//Do nothing, not opened within editor context
	}

}
 
Example 11
Project: gama   File: GamlSearchField.java   View source code 6 votes vote down vote up
public void search() {
	final IWorkbenchPart part = WorkbenchHelper.getActivePart();
	if (part instanceof IEditorPart) {
		final IEditorPart editor = (IEditorPart) part;
		final IWorkbenchPartSite site = editor.getSite();
		if (site != null) {
			final ISelectionProvider provider = site.getSelectionProvider();
			if (provider != null) {
				final ISelection viewSiteSelection = provider.getSelection();
				if (viewSiteSelection instanceof TextSelection) {
					final TextSelection textSelection = (TextSelection) viewSiteSelection;
					text.setText(textSelection.getText());
				}
			}
		}

	}
	activate(null);
	text.setFocus();

}
 
Example 12
Project: APICloud-Studio   File: StatusLineMessageTimerManager.java   View source code 6 votes vote down vote up
static IStatusLineManager getStatusLineManager()
{
	try
	{
		IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActivePart().getSite();
		return ((IViewSite) site).getActionBars().getStatusLineManager();
	}
	catch (Exception e)
	{
		// try to get the IStatusLineManager through an active editor
		try
		{
			return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
					.getEditorSite().getActionBars().getStatusLineManager();
		}
		catch (Exception e1)
		{
		}
	}
	return null;
}
 
Example 13
Project: mytourbook   File: Util.java   View source code 6 votes vote down vote up
/**
 * Clear all selection providers in all workench pages.
 */
public static void clearSelection() {

	final IWorkbenchWindow wbWin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (wbWin != null) {

		final IWorkbenchPage[] wbPages = wbWin.getPages();
		for (final IWorkbenchPage wbPage : wbPages) {

			final IWorkbenchPart wbWinPagePart = wbPage.getActivePart();
			if (wbWinPagePart != null) {

				final IWorkbenchPartSite site = wbWinPagePart.getSite();
				if (site != null) {

					final ISelectionProvider selectionProvider = site.getSelectionProvider();

					if (selectionProvider instanceof PostSelectionProvider) {
						((PostSelectionProvider) selectionProvider).clearSelection();
					}
				}
			}
		}
	}
}
 
Example 14
Project: OpenSPIFe   File: PlanTimeline.java   View source code 6 votes vote down vote up
/**
 * Sets the site and input for this editor then creates and initializes the actions.
 * Subclasses may extend this method, but should always call <code>super.init(site, input)
 * </code>.
 * @see org.eclipse.ui.IEditorPart#init(IEditorSite, IEditorInput)
 */
public void init(IWorkbenchPartSite site, PlanEditorModel planEditorModel) {
	super.init(site, planEditorModel.getEPlan());
	this.planEditorModel = planEditorModel;
	EPlan ePlan = planEditorModel.getEPlan();
	this.domain = TransactionUtils.getDomain(ePlan);
	this.moveThread = new MoveThread(ePlan, this);
	IPreferenceStore store = TimelinePlugin.getDefault().getPreferenceStore();
	if (store.getBoolean(TimelinePreferencePage.P_SNAP_TO_ACTIVE)) {
		setSnapTolerance(SnapToTimelineHandler.DEFAULT_TOLERANCE);
	}
	//FIXME:  Make stores consistent.  See also SnapToAssessment.isEnabled().
	setSnapToOrbitEnabled(TimelineConstants.TIMELINE_PREFERENCES.getBoolean(TimelinePreferencePage.P_SNAP_TO_ORBIT_ACTIVE));
	timelineServices = ClassRegistry.createInstances(PlanTimelineService.class);
	for (PlanTimelineService s : timelineServices) {
		s.setTimeline(this);
	}
}
 
Example 15
Project: OpenSPIFe   File: Timeline.java   View source code 6 votes vote down vote up
public void init(IWorkbenchPartSite site, T model) {
	this.site = site;
	this.model = model;
	this.timelineModel.eAdapters().add(timelineModelAdapter);
	if (site != null) {
		ISelectionProvider selectionProvider = site.getSelectionProvider();
		if (selectionProvider != null) {
			selectionProvider.addSelectionChangedListener(selectionListener);
		}
	}

	timelineServices = ClassRegistry.createInstances(TimelineService.class);
	for (TimelineService s : timelineServices) {
		s.setTimeline(this);
	}
}
 
Example 16
Project: OpenSPIFe   File: MergeTreeViewer.java   View source code 6 votes vote down vote up
public MergeTreeViewer(TreeTableComposite treeComposite, final TreeTableColumnConfiguration configuration, IWorkbenchPartSite site) {
	super(treeComposite, configuration, site);
	addFilter(new VisabilityFilter());
	treeComposite.getTree().addTreeListener(new PlanElementTreeListener()); // will be disposed with the Tree

	final Tree tree = getTree();
	tree.addMenuDetectListener(new MenuDetectListener() {
		@Override
		public void menuDetected(MenuDetectEvent e) {
			Point point = tree.toControl(e.x, e.y);
			Rectangle clientArea = tree.getClientArea();
			if (clientArea.y <= point.y && point.y < (clientArea.y + tree.getHeaderHeight())) {
				e.doit = false;
				int columnIndex = getColumnIndex(point.x);
				fillHeaderContextMenu(e.display, columnIndex, point, configuration.getColumns());
			}
		}
	});
}
 
Example 17
Project: OpenSPIFe   File: WorkbenchUtils.java   View source code 6 votes vote down vote up
/**
 * This function takes a workbench part site, which might be from a top-level view,
 * or from a top-level editor, or from a page-level editor in a multipage editor 
 * site.  The function finds the corresponding part for this site and activates it.
 * @param site
 */
public static void activate(IWorkbenchPartSite site) {
	try {
		IWorkbenchPart part;
		if (site instanceof MultiPageEditorSite) {
			part = ((MultiPageEditorSite)site).getMultiPageEditor();
		} else {
			part = site.getPart();
		}
		if (part == null) {
			return;
		}
		IWorkbenchPage page = site.getPage();
		if (page == null) {
			return;
		}
		page.activate(part);
	} catch (ThreadDeath td) {
		throw td;
	} catch (Throwable t) {
		Logger.getLogger(WorkbenchUtils.class).error("throwable in activate", t);
	}
}
 
Example 18
Project: OpenSPIFe   File: AbstractEnsembleEditorPart.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
    protected void attachModel(IEditorInput input, IWorkbenchPartSite site) {
		copyAttributes(cutHandler, ActionFactory.CUT);
		copyAttributes(copyHandler, ActionFactory.COPY);
		copyAttributes(pasteHandler, ActionFactory.PASTE);
//		copyAttributes(pasteSpecialHandler, EnsembleActionFactory.PASTE_SPECIAL);
		copyAttributes(deleteHandler, ActionFactory.DELETE);
		copyAttributes(selectAllHandler, ActionFactory.SELECT_ALL);
		getEditorSite().getKeyBindingService(); // Editors need to bind keyboard actions 
		
		IUndoContext undoContext = getUndoContext();
		undoHandler = new UndoActionHandler(site, undoContext);
		redoHandler = new RedoActionHandler(site, undoContext);
		cutHandler.init(site, undoContext);
		copyHandler.init(site, undoContext);
		pasteHandler.init(site, undoContext);
//		pasteSpecialHandler.setUndoContext(undoContext);
		deleteHandler.init(site, undoContext);
		
		updateHandlerEnablements();
    }
 
Example 19
Project: e4macs   File: BaseYankHandler.java   View source code 6 votes vote down vote up
/**
 * In the console context, use paste as
 * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
 * will not simulate keyboard input
 *  
 * @param event the ExecutionEvent
 * @param widget The consoles StyledText widget
 */
protected void paste(ExecutionEvent event, StyledText widget) {
		IWorkbenchPart apart = HandlerUtil.getActivePart(event);
		if (apart != null) {
			try {
				IWorkbenchPartSite site = apart.getSite();
				if (site != null) {
					IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
					if (service != null) {
						service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
						KillRing.getInstance().setYanked(true);
					}
				}
			} catch (CommandException e) {
			}
		}
}
 
Example 20
Project: OpenSPIFe   File: TemplatePlanViewAddAction.java   View source code 6 votes vote down vote up
public TemplatePlanViewAddAction(String text, int style, TemplatePlanView templatePlanView) {
	super(text, style);
	this.templatePlanView = templatePlanView;
	addButtonImageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(EditorPlugin.ID, "icons/add.png");
	this.setEnabled(false);
	IWorkbenchPartSite site = templatePlanView.getSite();
	if(partListener == null) {
		partListener = new PartListener();
	}
	if(site != null) {
		IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow();
		if(workbenchWindow != null) {
			IPartService partService = workbenchWindow.getPartService();
			if(partService != null) {
				partService.addPartListener(partListener);
			}
		}
	}
}
 
Example 21
Project: OpenSPIFe   File: MultiPagePlanEditor.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isSaveOnCloseNeeded() {
	// workaround for SPF-6678 "Dirty bit is only set when focus is removed from field in Template View, Details View "
	IWorkbenchPartSite site = getSite();
	if (site != null) {
		IWorkbenchPage page = site.getPage();
		IViewReference[] viewReferences = page.getViewReferences();
		for (IViewReference iViewReference : viewReferences) {
			IViewPart viewPart = iViewReference.getView(false);
			if(viewPart != null) {
				Object adapter = viewPart.getAdapter(IPage.class);
				if(adapter instanceof DetailPage) {
					DetailPage detailPage = (DetailPage) adapter;
					if(detailPage.hasSheet()) {
						this.setFocus();
						break;
					}
				}
			}	
		}			
	}
	// end workaround
	return super.isSaveOnCloseNeeded();
}
 
Example 22
Project: Eclipse-Postfix-Code-Completion   File: JavaEditor.java   View source code 6 votes vote down vote up
/**
 * Makes sure that the editor's folding state is correct the next time
 * it becomes visible. If it already is visible, it toggles the folding
 * state. If not, it either registers a part listener to toggle folding
 * when the editor becomes visible, or cancels an already registered
 * runner.
 */
public void runWhenNextVisible() {
	// if there is one already: toggling twice is the identity
	if (fFoldingRunner != null) {
		fFoldingRunner.cancel();
		return;
	}
	IWorkbenchPartSite site= getSite();
	if (site != null) {
		IWorkbenchPage page= site.getPage();
		if (!page.isPartVisible(JavaEditor.this)) {
			// if we're not visible - defer until visible
			fPage= page;
			fFoldingRunner= this;
			page.addPartListener(this);
			return;
		}
	}
	// we're visible - run now
	toggleFolding();
}
 
Example 23
Project: Eclipse-Postfix-Code-Completion   File: SemanticHighlightingReconciler.java   View source code 6 votes vote down vote up
/**
 * 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 24
Project: Eclipse-Postfix-Code-Completion   File: JavaReconciler.java   View source code 6 votes vote down vote up
@Override
public void uninstall() {

	IWorkbenchPartSite site= fTextEditor.getSite();
	IWorkbenchWindow window= site.getWorkbenchWindow();
	window.getPartService().removePartListener(fPartListener);
	fPartListener= null;

	Shell shell= window.getShell();
	if (shell != null && !shell.isDisposed())
		shell.removeShellListener(fActivationListener);
	fActivationListener= null;

	JavaCore.removeElementChangedListener(fJavaElementChangedListener);
	fJavaElementChangedListener= null;

	IWorkspace workspace= JavaPlugin.getWorkspace();
	workspace.removeResourceChangeListener(fResourceChangeListener);
	fResourceChangeListener= null;

	JavaPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
	fPropertyChangeListener= null;

	super.uninstall();
}
 
Example 25
Project: Eclipse-Postfix-Code-Completion   File: ViewActionGroup.java   View source code 6 votes vote down vote up
public ViewActionGroup(int mode, IPropertyChangeListener changeListener, IWorkbenchPartSite site) {
	fChangeListener= changeListener;
	fSite= site;
	if (fChangeListener == null) {
		fChangeListener = new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {}
		};
	}
	fFilterActionGroup= new WorkingSetFilterActionGroup(site, fChangeListener);
	fShowActionGroup= new WorkingSetShowActionGroup(site);
	fWorkingSetAssignementAction= new ConfigureWorkingSetAssignementAction(site);

	ISelectionProvider selectionProvider= site.getSelectionProvider();
	selectionProvider.addSelectionChangedListener(fWorkingSetAssignementAction);

	fMode= mode;
	if (fMode == SHOW_WORKING_SETS)
		fActiveActionGroup= fShowActionGroup;
	else
		fActiveActionGroup= fFilterActionGroup;
}
 
Example 26
Project: Eclipse-Postfix-Code-Completion   File: WorkingSetFilterActionGroup.java   View source code 6 votes vote down vote up
public WorkingSetFilterActionGroup(IWorkbenchPartSite site, IPropertyChangeListener changeListener) {
	Assert.isNotNull(site);
	Assert.isNotNull(changeListener);

	fChangeListener= changeListener;
	fWorkbenchPage= site.getPage();
	fAllowWindowWorkingSetByDefault= true;
	fClearWorkingSetAction= new ClearWorkingSetAction(this);
	fSelectWorkingSetAction= new SelectWorkingSetAction(this, site);
	fEditWorkingSetAction= new EditWorkingSetAction(this, site);

	fWorkingSetListener= new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			doPropertyChange(event);
		}
	};
	fWorkingSetFilter= new WorkingSetFilter();

	IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
	manager.addPropertyChangeListener(fWorkingSetListener);

	if (useWindowWorkingSetByDefault()) {
		setWorkingSet(site.getPage().getAggregateWorkingSet(), false);
	}
}
 
Example 27
Project: gef-gwt   File: RetargetAction.java   View source code 6 votes vote down vote up
/**
 * A workbench part has been deactivated. Disconnect from it.
 * 
 * @param part
 *            the workbench part that has been deactivated
 */
public void partDeactivated(IWorkbenchPart part) {
	super.partDeactivated(part);
	IWorkbenchPartSite site = part.getSite();
	SubActionBars bars = (SubActionBars) ((PartSite) site).getActionBars();
	bars.removePropertyChangeListener(propertyChangeListener);

	IWorkbenchPart activePart = part.getSite().getPage().getActivePart();
	if (activePart != null) {
		// We are going to get a part activated message so don't bother
		// setting the
		// action handler to null. This prevents enablement flash in the
		// toolbar
		return;
	}

	setActionHandler(null);
}
 
Example 28
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JavaEditor.java   View source code 6 votes vote down vote up
/**
 * Makes sure that the editor's folding state is correct the next time
 * it becomes visible. If it already is visible, it toggles the folding
 * state. If not, it either registers a part listener to toggle folding
 * when the editor becomes visible, or cancels an already registered
 * runner.
 */
public void runWhenNextVisible() {
	// if there is one already: toggling twice is the identity
	if (fFoldingRunner != null) {
		fFoldingRunner.cancel();
		return;
	}
	IWorkbenchPartSite site= getSite();
	if (site != null) {
		IWorkbenchPage page= site.getPage();
		if (!page.isPartVisible(JavaEditor.this)) {
			// if we're not visible - defer until visible
			fPage= page;
			fFoldingRunner= this;
			page.addPartListener(this);
			return;
		}
	}
	// we're visible - run now
	toggleFolding();
}
 
Example 29
Project: Eclipse-Postfix-Code-Completion-Juno38   File: SemanticHighlightingReconciler.java   View source code 6 votes vote down vote up
/**
 * 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 30
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JavaReconciler.java   View source code 6 votes vote down vote up
@Override
public void uninstall() {

	IWorkbenchPartSite site= fTextEditor.getSite();
	IWorkbenchWindow window= site.getWorkbenchWindow();
	window.getPartService().removePartListener(fPartListener);
	fPartListener= null;

	Shell shell= window.getShell();
	if (shell != null && !shell.isDisposed())
		shell.removeShellListener(fActivationListener);
	fActivationListener= null;

	JavaCore.removeElementChangedListener(fJavaElementChangedListener);
	fJavaElementChangedListener= null;

	IWorkspace workspace= JavaPlugin.getWorkspace();
	workspace.removeResourceChangeListener(fResourceChangeListener);
	fResourceChangeListener= null;

	JavaPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
	fPropertyChangeListener= null;

	super.uninstall();
}
 
Example 31
Project: Eclipse-Postfix-Code-Completion-Juno38   File: WorkingSetFilterActionGroup.java   View source code 6 votes vote down vote up
public WorkingSetFilterActionGroup(IWorkbenchPartSite site, IPropertyChangeListener changeListener) {
	Assert.isNotNull(site);
	Assert.isNotNull(changeListener);

	fChangeListener= changeListener;
	fWorkbenchPage= site.getPage();
	fAllowWindowWorkingSetByDefault= true;
	fClearWorkingSetAction= new ClearWorkingSetAction(this);
	fSelectWorkingSetAction= new SelectWorkingSetAction(this, site);
	fEditWorkingSetAction= new EditWorkingSetAction(this, site);

	fWorkingSetListener= new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			doPropertyChange(event);
		}
	};
	fWorkingSetFilter= new WorkingSetFilter();

	IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
	manager.addPropertyChangeListener(fWorkingSetListener);

	if (useWindowWorkingSetByDefault()) {
		setWorkingSet(site.getPage().getAggregateWorkingSet(), false);
	}
}
 
Example 32
Project: eZooKeeper   File: ViewerFactory.java   View source code 5 votes vote down vote up
/**
 * Create a new {@link TableViewer} with {@link DataModel} elements.
 * 
 * @param site The {@link IWorkbenchPartSite} used to register the table's context menu.
 * @param table The {@link Table}.
 * @param dataModelClass The {@link DataModel} element {@link Class}.
 * @param dataModelElementType The {@link DataModel} {@link IElementType}.
 * @param input The {@link TableViewer} input.
 * @param inputElementType The input {@link IElementType}.
 * @return A new {@link TableViewer}.
 */
public static TableViewer createDataModelTableViewer(IWorkbenchPartSite site, Table table, Class<?> dataModelClass,
        final IElementType dataModelElementType, Object input, IElementType inputElementType) {

    TableViewer tableViewer = createTableViewer(table, dataModelClass, dataModelElementType, input,
            inputElementType, new DataModelElementBinding());

    List<BaseAction> tableActions = dataModelElementType.getActions();
    if (tableActions != null) {
        for (BaseAction action : tableActions) {
            action.setSelectionProvider(tableViewer);
        }

        MenuManager menuManager = new MenuManager("#PopupMenu");
        menuManager.setRemoveAllWhenShown(true);
        menuManager.addMenuListener(new IMenuListener() {

            public void menuAboutToShow(IMenuManager manager) {
                dataModelElementType.fillContextMenu(manager);
            }

        });

        Menu menu = menuManager.createContextMenu(table);
        table.setMenu(menu);
        site.registerContextMenu(menuManager, tableViewer);
    }

    return tableViewer;
}
 
Example 33
Project: neoscada   File: VisualInterfaceFactory.java   View source code 5 votes vote down vote up
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
    final VisualInterfaceViewInstance instance = new VisualInterfaceViewInstance ( viewManager, viewManagerContext, viewHolder, descriptor, site.getService ( IEvaluationService.class ) );
    instance.init ();
    return instance;
}
 
Example 34
Project: neoscada   File: ChartViewFactory.java   View source code 5 votes vote down vote up
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
    final ChartView view = new ChartView ( viewManagerContext, manager, descriptor, viewHolder, (IEvaluationService)site.getService ( IEvaluationService.class ), true );
    view.init ();
    return view;
}
 
Example 35
Project: neoscada   File: ServersViewer.java   View source code 5 votes vote down vote up
private void hookContextMenu ( final IWorkbenchPartSite site )
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
    this.viewer.getControl ().setMenu ( menu );
    site.registerContextMenu ( menuMgr, this.viewer );
}
 
Example 36
Project: scanning   File: PageUtil.java   View source code 5 votes vote down vote up
/**
 * Gets the page, even during startup.
 * @return the page
 */
public static IWorkbenchPage getPage(IWorkbenchPartSite site) {
	if (site != null) {
		IWorkbenchPage page = site.getPage();
		if (page != null) return page;
	}
	IWorkbenchPage activePage = PageUtil.getActivePage();
	if (activePage!=null) return activePage;
	return PageUtil.getDefaultPage();
}
 
Example 37
Project: scanning   File: Util.java   View source code 5 votes vote down vote up
/**
 * Gets the page, even during startup.
 * @return the page
 */
public static IWorkbenchPage getPage(IWorkbenchPartSite site) {
	if (site != null) {
		IWorkbenchPage page = site.getPage();
		if (page != null) return page;
	}
	IWorkbenchPage activePage = getActivePage();
	if (activePage!=null) return activePage;
	return getDefaultPage();
}
 
Example 38
Project: team-explorer-everywhere   File: LegacyActionKeyBindingSupport.java   View source code 5 votes vote down vote up
private LegacyActionKeyBindingSupport(
    final IWorkbench workbench,
    final Shell shell,
    final IWorkbenchPartSite site) {
    Check.notNull(workbench, "workbench"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    workbenchCommandSupport = workbench.getCommandSupport();
    this.shell = shell;
    this.site = site;
}
 
Example 39
Project: subclipse   File: Utilities.java   View source code 5 votes vote down vote up
public static IWorkbenchPartSite findSite(Control c) {
	while (c != null && !c.isDisposed()) {
		Object data= c.getData();
		if (data instanceof IWorkbenchPart)
			return ((IWorkbenchPart)data).getSite();
		c= c.getParent();
	}
	return null;
}
 
Example 40
Project: Notepad4e   File: Note.java   View source code 5 votes vote down vote up
/**
 * 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()));
	}
}