org.eclipse.ui.IPartService Java Examples

The following examples show how to use org.eclipse.ui.IPartService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractPDFViewerRunnable.java    From tlaplus with MIT License 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 #2
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void close() {
	if (!popup.isDisposed()) {
		// Composite c = view.getComponent();
		if (referenceComposite != null && !referenceComposite.isDisposed()) {
			referenceComposite.removeControlListener(listener);
		}
		final IPartService ps = ((IWorkbenchPart) view).getSite().getService(IPartService.class);
		if (ps != null) {
			ps.removePartListener(pl2);
		}
		if (!popup.getParent().isDisposed()) {
			popup.getParent().removeControlListener(listener);
			popup.getParent().getShell().removeShellListener(listener);
		}
		timer.cancel();
		popup.dispose();
	}
}
 
Example #3
Source File: DropWorkbenchChangeListener.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void hookWindow(IWorkbenchWindow window) {
	if (window == null) {
		return;
	}
	window.addPageListener(this);
	window.addPerspectiveListener(this);
	IPartService partService = (IPartService) window.getService(IPartService.class);
	partService.addPartListener(this);
	windowChanged(window);
}
 
Example #4
Source File: EditorBoundViewPart.java    From depan with Apache License 2.0 5 votes vote down vote up
protected E getActiveEditor() {
  IWorkbenchWindow wndo = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  if (null == wndo) {
    return null;
  }

  IPartService srvc = wndo.getPartService();
  return getAcceptableEditor(srvc.getActivePart());
}
 
Example #5
Source File: GamlEditor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void assignBoxPartListener() {
	final IPartService partService = getSite().getWorkbenchWindow().getPartService();
	if (partService == null) { return; }
	if (partListeners == null) {
		partListeners = new HashMap<>();
	}
	final IPartListener2 oldListener = partListeners.get(partService);
	if (oldListener == null) {
		final IPartListener2 listener = new BoxDecoratorPartListener();
		partService.addPartListener(listener);
		partListeners.put(partService, listener);
	}
}
 
Example #6
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public DisplayOverlay(final LayeredDisplayView view, final Composite c,
		final IOverlayProvider<OverlayInfo> provider) {
	this.createExtraInfo = provider != null;
	this.view = view;
	final IPartService ps = ((IWorkbenchPart) view).getSite().getService(IPartService.class);
	ps.addPartListener(pl2);
	referenceComposite = c;
	// parentShell = c.getShell();
	popup = new Shell(c.getShell(), SWT.NO_TRIM | SWT.NO_FOCUS);
	popup.setAlpha(140);
	final FillLayout layout = new FillLayout();
	layout.type = SWT.VERTICAL;
	layout.spacing = 10;
	popup.setLayout(layout);
	popup.setBackground(IGamaColors.BLACK.color());
	createPopupControl();
	popup.setAlpha(140);
	popup.layout();
	c.getShell().addShellListener(listener);
	// parentShell.addControlListener(listener);
	c.addControlListener(listener);
	if (provider != null) {
		provider.setTarget(new ThreadedOverlayUpdater(this), view.getDisplaySurface());
	}
	// if (GamaPreferences.Displays.CORE_SHOW_FPS.getValue()) {
	timer.schedule(new FPSTask(), 0, 1000);
	// }
}
 
Example #7
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void windowClosed(IWorkbenchWindow window)
{
	IPartService partService = window.getPartService();
	if (partService != null)
	{
		partService.removePartListener(fPartListener);
	}
	window.removePerspectiveListener(fPerspectiveListener);
}
 
Example #8
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void windowOpened(IWorkbenchWindow window)
{
	IPartService partService = window.getPartService();
	if (partService != null)
	{
		partService.addPartListener(fPartListener);
	}
	window.addPerspectiveListener(fPerspectiveListener);
}
 
Example #9
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void addPartListener()
{
	try
	{
		IWorkbench workbench = PlatformUI.getWorkbench();
		if (workbench != null)
		{
			IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
			IPartService partService;
			for (IWorkbenchWindow window : windows)
			{
				partService = window.getPartService();
				if (partService != null)
				{
					partService.addPartListener(fPartListener);
				}
				window.addPerspectiveListener(fPerspectiveListener);
			}

			// Listen on any future windows
			PlatformUI.getWorkbench().addWindowListener(fWindowListener);
		}
	}
	catch (Exception e)
	{
		// ignore, may be running headless, like in tests
	}
}
 
Example #10
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void removePartListener()
{
	IWorkbench workbench = null;
	try
	{
		workbench = PlatformUI.getWorkbench();
	}
	catch (Exception e)
	{
		// ignore, may be running headless, like in tests
	}
	if (workbench != null)
	{
		IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
		IPartService partService;
		for (IWorkbenchWindow window : windows)
		{
			partService = window.getPartService();
			if (partService != null)
			{
				partService.removePartListener(fPartListener);
			}
			window.removePerspectiveListener(fPerspectiveListener);
		}
		PlatformUI.getWorkbench().removeWindowListener(fWindowListener);
	}
}
 
Example #11
Source File: OccurrencesSearchMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RetargetAction createSubmenuAction(IPartService partService, String actionID, String text, String actionDefinitionId) {
	RetargetAction action= new RetargetAction(actionID, text);
	action.setActionDefinitionId(actionDefinitionId);

	partService.addPartListener(action);
	IWorkbenchPart activePart = partService.getActivePart();
	if (activePart != null) {
		action.partActivated(activePart);
	}
	return action;
}
 
Example #12
Source File: SurroundWithTemplateMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init(IWorkbenchWindow window) {
	if (fPartService != null) {
		fPartService.removePartListener(fPartListener);
		fPartService= null;
	}

	if (window != null) {
		IPartService partService= window.getPartService();
		if (partService != null) {
			fPartService= partService;
			partService.addPartListener(fPartListener);
		}
	}
}
 
Example #13
Source File: WorkbenchUtils.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static IWorkbenchPart getActivePart(IWorkbenchPartSite site) {
	IWorkbenchWindow window = site.getWorkbenchWindow();
	IPartService service = window.getPartService();
	return service.getActivePart();
}
 
Example #14
Source File: EditorManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void initialize() {
	IWorkbenchWindow window = WorkbenchUtils.getActiveWorkbenchWindow();
	IPartService partService = window.getPartService();
	partService.addPartListener(new ViewPartListener());
}
 
Example #15
Source File: BTEditor.java    From jbt with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (!(input instanceof BTEditorInput)) {
		throw new PartInitException("Illegal IEditorInput. Must be "
				+ BTEditorInput.class.getCanonicalName());
	}

	setSite(site);
	setInputWithNotify(input);
	BTEditorInput editorInput = (BTEditorInput) input;
	setPartName(input.getName());
	this.openGuardEditors = new Hashtable<BTNode, BTEditor>();

	/* Set the IPartListener that will handle close events. */
	IPartService partService = (IPartService) this.getSite().getService(IPartService.class);
	partService.addPartListener(new BTEditorPartListener());

	if (editorInput.isFromFile()) {
		/* If the tree comes from a file, load the file. */
		try {
			this.tree = BTXMLManager.load(editorInput.getTreeName());
			this.tree.addTreeModifiedListener(this);
			this.dirty = false;
		} catch (IOException e) {
			throw new PartInitException("There were errors while loading the tree: "
					+ e.getMessage(), e);
		}
	} else if (editorInput.isFromGuard()) {
		/*
		 * If the tree comes from a guard, we have to construct a new tree
		 * whose root is the guard.
		 */
		this.tree = new BT();
		this.tree.addTreeModifiedListener(this);

		BTEditor activeEditor = Utilities.getActiveBTEditor();
		this.guardTree = activeEditor.getBT();

		String[] pieces = editorInput.getTreeName().split(File.pathSeparator);
		this.guardNode = this.guardTree.findNode(new Identifier(pieces[1]));

		/*
		 * Important: the root node (type ROOT) of the guard's tree is not a
		 * normal ROOT, since it has no name. Therefore, we clone the
		 * original ROOT type and remove its ability to provide a name.
		 */
		ConceptualBTNode conceptualNoNameRoot = NodesLoader.getNode(
				NodeInternalType.ROOT.toString(), null).clone();
		conceptualNoNameRoot.setHasName(false);
		BTNode noNameRoot = this.tree.createNode(conceptualNoNameRoot);

		BTNode guard = this.guardNode.getGuard();

		if (guard != null) {
			/* If the node had a guard, then the editor is not dirty. */
			BTNode clonedGuard = guard.clone();
			clonedGuard.setParent(noNameRoot);
			noNameRoot.addChild(clonedGuard);
			this.dirty = false;
		} else {
			/* Otherwise, the editor is dirty. */
			this.dirty = true;
		}

		this.tree.setRoot(noNameRoot);

		this.setTitleImage(ApplicationIcons.getIcon(IconsPaths.GUARD));
	} else {
		/* Otherwise, create a new empty BT. */
		this.tree = new BT();
		this.tree.addTreeModifiedListener(this);
		tree.setRoot(tree.createNode(NodesLoader.getNode(NodeInternalType.ROOT.toString(), null)));
		this.dirty = true;
	}
}
 
Example #16
Source File: ICEResourceView.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation overrides the ViewPart.createPartControl method to create
 * and draw the TreeViewer before registering it as a selection provider.
 * 
 * @param parent
 *            The Composite used to create the TreeViewer.
 */
@Override
public void createPartControl(Composite parent) {

	// Create a TabFolder to manage tabs
	tabFolder = new TabFolder(parent, SWT.NONE);

	// Create pages (TabItems) for text files and images
	TabItem textTab = new TabItem(tabFolder, SWT.NONE, 0);
	textTab.setText("Files");
	TabItem imageTab = new TabItem(tabFolder, SWT.NONE, 1);
	imageTab.setText("Images");
	TabItem plotTab = new TabItem(tabFolder, SWT.NONE, 2);
	plotTab.setText("Plots");

	// Create the tool bar and buttons for the view
	createActions();

	// Initialize the TreeViewer
	fileTreeViewer = new TreeViewer(tabFolder);
	imageTreeViewer = new TreeViewer(tabFolder);
	// Create content and label providers
	initializeTreeViewer(fileTreeViewer);
	initializeTreeViewer(imageTreeViewer);
	// Register the tree to the tabs
	textTab.setControl(fileTreeViewer.getControl());
	imageTab.setControl(imageTreeViewer.getControl());
	// Register this view as a SelectionProvider
	getSite().setSelectionProvider(fileTreeViewer);
	getSite().setSelectionProvider(imageTreeViewer);
	// Registered the view as a double click listener of the TreeViewer
	fileTreeViewer.addDoubleClickListener(this);
	imageTreeViewer.addDoubleClickListener(this);

	// Add a listener to catch tab selection changes.
	// NOTE: In Windows, this event is fired instantly, so this listener
	// needs to be declared after everything else is initialized!
	tabFolder.addListener(SWT.Selection, new Listener() {
		@Override
		public void handleEvent(Event event) {
			// If tabs are changed while playing, stop playing.
			if (playAction.isInPlayState()) {
				playAction.stop();
			}
			// Set the TreeViewer input to the selected tab
			setTreeContent(tabFolder.indexOf((TabItem) event.item));
		}
	});

	// Create the Table and table viewer for the Plot tab
	Table listTable = new Table(tabFolder, SWT.FLAT);
	DefaultEventTableViewer<VizResource> listTableViewer = new DefaultEventTableViewer<VizResource>(
			plotList, listTable, plotList);
	// Register the table control with the plot tab
	plotTab.setControl(listTable);

	// Check if there is currently an active ICEFormEditor. If so, update
	// the currently active editor and related UI pieces.
	IEditorPart activeEditor = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	if (activeEditor != null && activeEditor instanceof ICEFormEditor) {
		if (activeEditor != editor) {
			setActiveEditor((ICEFormEditor) activeEditor);
		}
	} else {
		// Get a list of all the currently open editors
		IWorkbenchPage workbenchPage = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage();
		IEditorReference[] editorRefs = workbenchPage.getEditorReferences();

		if (editorRefs != null && editorRefs.length > 0) {
			// Begin iterating through all the editors, looking for one
			// that's an ICEFormEditor
			for (IEditorReference e : editorRefs) {
				// If it's an ICEFormEditor, set it as the active editor
				if (e.getId().equals(ICEFormEditor.ID)) {
					setActiveEditor((ICEFormEditor) e.getEditor(false));
					break;
				}
			}
		}
	}

	// Register as a listener to the part service so that the view can
	// update when the active ICEFormEditor changes.
	IPartService partService = getSite().getWorkbenchWindow()
			.getPartService();
	partService.addPartListener(this);

	return;
}
 
Example #17
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IWorkbenchPart getActivePart() {
	IWorkbenchWindow window= getSite().getWorkbenchWindow();
	IPartService service= window.getPartService();
	IWorkbenchPart part= service.getActivePart();
	return part;
}
 
Example #18
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 4 votes vote down vote up
private IWorkbenchPart getActivePart() {
	IWorkbenchWindow window = getSite().getWorkbenchWindow();
	IPartService service = window.getPartService();
	IWorkbenchPart part = service.getActivePart();
	return part;
}
 
Example #19
Source File: ModelEditor.java    From tlaplus with MIT License 4 votes vote down vote up
/**
    * Initialize the editor
    */
   @Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
       // TLCUIActivator.getDefault().logDebug("entering ModelEditor#init(IEditorSite site, IEditorInput input)");
       super.init(site, input);

       // grab the input
	final FileEditorInput finput = getFileEditorInput();

	// the file might not exist anymore (e.g. manually removed by the user) 
	if ((finput == null) || !finput.exists()) {
		throw new PartInitException("Editor input does not exist: " + finput.getName());
	}
	
       model = TLCModelFactory.getBy(finput.getFile());
       
       int openTabsValue = 0;
       try {
		openTabsValue = model.getLaunchConfiguration().getAttribute(IModelConfigurationConstants.EDITOR_OPEN_TABS, 0);
       } catch (CoreException e) { }

       final boolean mustShowResultsPage
       			= model.isSnapshot()
       				|| parsePotentialAssociatedTLCRunToDetermineWhetherResultsPageMustBeShown();
	final IPreferenceStore ips = TLCUIActivator.getDefault().getPreferenceStore();
       if (openTabsValue == IModelConfigurationConstants.EDITOR_OPEN_TAB_NONE) {
		pagesToAdd = mustShowResultsPage
								? new BasicFormPage[] { new MainModelPage(this), new ResultPage(this) }
								: new BasicFormPage[] { new MainModelPage(this) };
       } else {
       	final ArrayList<BasicFormPage> editorPages = new ArrayList<>();
           
       	editorPages.add(new MainModelPage(this));
		if ((openTabsValue & IModelConfigurationConstants.EDITOR_OPEN_TAB_ADVANCED_MODEL) != 0) {
			editorPages.add(new AdvancedModelPage(this));
       	}
		if ((openTabsValue & IModelConfigurationConstants.EDITOR_OPEN_TAB_ADVANCED_TLC) != 0) {
			editorPages.add(new AdvancedTLCOptionsPage(this));
       	}
		if (mustShowResultsPage
						|| ((openTabsValue & IModelConfigurationConstants.EDITOR_OPEN_TAB_RESULTS) != 0)) {
			editorPages.add(new ResultPage(this));
        	if (ips.getBoolean(IModelEditorPreferenceConstants.I_MODEL_EDITOR_SHOW_ECE_AS_TAB)) {
        		editorPages.add(new EvaluateConstantExpressionPage(this));
        	}
        	
        	if (mustShowResultsPage) {
        		final int openTabState = getModel().getOpenTabsValue();
        		updateOpenTabsState(openTabState | IModelConfigurationConstants.EDITOR_OPEN_TAB_RESULTS);	        		
        	}
       	}

           pagesToAdd = editorPages.toArray(new BasicFormPage[editorPages.size()]);
       }
       
       ips.addPropertyChangeListener(preferenceChangeListener);
       
       
       // setContentDescription(path.toString());
       if (model.isSnapshot()) {
       	final String date = SIMPLE_DATE_FORMAT.format(model.getSnapshotTimeStamp());
           this.setPartName(model.getSnapshotFor().getName() + " (" + date + ")");
       } else {
       	this.setPartName(model.getName());
       }
       this.setTitleToolTip(model.getFile().getLocation().toOSString());

       // add a listener that will update the tlc error view when a model editor
       // is made visible
       IPartService service = (IPartService) getSite().getService(IPartService.class);
       service.addPartListener(ModelEditorPartListener.getDefault());

       /*
        * Install resource change listener on the workspace root to react on any changes in th current spec
        */
       ResourcesPlugin.getWorkspace().addResourceChangeListener(workspaceResourceChangeListener,
               IResourceChangeEvent.POST_BUILD);

       // update the spec object of the helper
       helper.resetSpecNames();

       // initial re-validate the pages, which are already loaded
       UIHelper.runUIAsync(validateRunable);
       // TLCUIActivator.getDefault().logDebug("leaving ModelEditor#init(IEditorSite site, IEditorInput input)");

       
       // Asynchronously register a PageChangedListener to now cause cyclic part init warnings
	UIHelper.runUIAsync(new Runnable() {
		public void run() {
			addPageChangedListener(pageChangedListener);
		}
	});
	
	model.add(modelStateListener);
}