/** * @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); } }); }
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); } }
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(); } }
@Override public void updateElement(UIElement element, Map parameters) { IServiceLocator serviceLocator = element.getServiceLocator(); IPartService partService = (IPartService)serviceLocator.getService(IPartService.class); partService.addPartListener(ACTIVE_EDITOR_LISTENER); // adding the same listener multiple times is ok and ignored PlanModifierFactory elementFactory = (PlanModifierFactory)serviceLocator.getService(PlanModifierFactory.class); IPlanModifier planModifier = getCurrentPlanModifier(parameters); PlanModifierFactory planFactory = PlanModifierRegistry.getInstance().getFactory(planModifier); if (elementFactory != null) { if (elementFactory == planFactory) { element.setChecked(true); } else { element.setChecked(false); } } else if (PLAN_MODIFIER_FACTORIES.size() == 2) { boolean checked = !(planModifier instanceof DirectPlanModifier); element.setChecked(checked); if (planFactory != null) { element.setTooltip(planFactory.getName()); element.setIcon(planFactory.getImageDescriptor()); } } }
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); } } } }
public void addListeners() { try { IWorkbench workbench = PlatformUI.getWorkbench(); // Add a WorkbenchListener workbenchListener = new ConvertigoWorkbenchListener(); workbench.addWorkbenchListener(workbenchListener); // Add a WindowListener windowListener = new ConvertigoWindowListener(); workbench.addWindowListener(windowListener); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { // Add a PerspectiveListener if (perspectiveListener == null) { perspectiveListener = new ConvertigoPerspectiveListener(); activeWorkbenchWindow.addPerspectiveListener(perspectiveListener); } // Add a PartListener if (partListener == null) { partListener = new ConvertigoPartListener(); IPartService partService = activeWorkbenchWindow.getPartService(); partService.addPartListener(partListener); } } } catch (IllegalStateException e) { studioLog.error("Could not add listeners to plugin."+ e.getMessage()); } }
public void earlyStartup() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench.getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { if (perspectiveListener == null) { perspectiveListener = new ConvertigoPerspectiveListener(); window.addPerspectiveListener(perspectiveListener); } if (partListener == null) { partListener = new ConvertigoPartListener(); IPartService partService = window.getPartService(); partService.addPartListener(partListener); } // Opens Convertigo perspective try { studioLog.message("Opening Convertigo perspective."); workbench.showPerspective(ConvertigoPlugin.PLUGIN_PERSPECTIVE_ID, window); } catch (WorkbenchException e) { studioLog.error("Could not open Convertigo perspective.\n" + e.getMessage()); } } } }); }
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); }
@Override public void dispose() { if(partListener != null) { final IWorkbenchWindow window = getSite().getWorkbenchWindow(); final IPartService svc = window.getPartService(); svc.removePartListener(partListener); partListener = null; } super.dispose(); }
protected E getActiveEditor() { IWorkbenchWindow wndo = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (null == wndo) { return null; } IPartService srvc = wndo.getPartService(); return getAcceptableEditor(srvc.getActivePart()); }
private void assignBoxPartListener() { final IPartService partService = getSite().getWorkbenchWindow().getPartService(); if (partService == null) { return; } if (partListeners == null) { partListeners = new HashMap<IPartService, IPartListener2>(); } final IPartListener2 oldListener = partListeners.get(partService); if (oldListener == null) { final IPartListener2 listener = new BoxDecoratorPartListener(); partService.addPartListener(listener); partListeners.put(partService, listener); } }
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); } }
public void windowClosed(IWorkbenchWindow window) { IPartService partService = window.getPartService(); if (partService != null) { partService.removePartListener(fPartListener); } window.removePerspectiveListener(fPerspectiveListener); }
public void windowOpened(IWorkbenchWindow window) { IPartService partService = window.getPartService(); if (partService != null) { partService.addPartListener(fPartListener); } window.addPerspectiveListener(fPerspectiveListener); }
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 } }
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); } }
@Override @SuppressWarnings("unchecked") public final void updateElement(UIElement element, Map parameters) { IServiceLocator serviceLocator = element.getServiceLocator(); IPartService partService = (IPartService) serviceLocator .getService(IPartService.class); installListeners(partService); updateEnablement(); }
public void dispose() { IWorkbenchPartSite site = templatePlanView.getSite(); if(partListener != null) { if(site != null) { IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow(); if(workbenchWindow != null) { IPartService partService = workbenchWindow.getPartService(); partService.removePartListener(partListener); } } } addButtonImageDescriptor = null; }
private void registerActions(IEditorSite site) { final IActionBars bars = site.getActionBars(); final IToolBarManager manager = bars.getToolBarManager(); for (PlanEditorContributionItem item : ClassRegistry.createInstances(PlanEditorContributionItem.class, new Class[] {IPartService.class}, new Object[] {getSite().getPage()})) { manager.add(item); } bars.updateActionBars(); }
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; }
/** * {@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); } } }
public void hookWindow(IWorkbenchWindow window) { if (window == null) { return; } window.addPageListener(this); window.addPerspectiveListener(this); IPartService partService = window.getService(IPartService.class); partService.addPartListener(this); windowChanged(window); }
@Override public void createPartControl(Composite parent) { partService = (IPartService) getSite().getService(IPartService.class); watchDogViewListener = new WatchDogViewListener(this); partService.addPartListener(watchDogViewListener); this.parent = parent; scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); scrolledComposite.setLayout(new FillLayout()); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); scrolledComposite.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { Rectangle r = scrolledComposite.getClientArea(); scrolledComposite.setMinSize( oneColumn.computeSize(r.width, SWT.DEFAULT)); } }); oneColumn = UIUtils.createGridedComposite(scrolledComposite, 1); scrolledComposite.setContent(oneColumn); if (!WatchDogGlobals.isActive) { createInactiveViewContent(); } else { calculateTimes(); latestDebugIntervals = intervalStatistics .getLatestDebugIntervals(NUMBER_OF_INTERVALS_TO_SHOW); if (selectedDebugIntervalShouldBeReset()) { selectedDebugInterval = !latestDebugIntervals.isEmpty() ? latestDebugIntervals.get(0) : null; } createActiveView(); } // Always create refresh link, even when statistics are not shown createRefreshLink(); }
/** * Create contents of the view part. * * @param parent */ @Override public void createPartControl(Composite parent) { setContentDescription(""); tabFolder = new TabFolder(parent, SWT.NONE); final IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow(); if(workbenchWindow != null ) { IPartService partService = workbenchWindow.getPartService(); if (partService != null ) partService.addPartListener(this); } edgeSummaryAll = RuntimeModel.getInstance().getSummaryInfo(); micTab = new TabItem(tabFolder, SWT.NONE); micTab.setText("MIC"); mircTab = new TabItem(tabFolder, SWT.NONE); mircTab.setText("MIRC"); mimTab = new TabItem(tabFolder, SWT.NONE); mimTab.setText("MIM"); mcbiTab = new TabItem(tabFolder, SWT.NONE); mcbiTab.setText("MCBI"); tableViewer = new RankedTableViewer(tabFolder, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); setControlTab(micTab); setControlTab(mircTab); setControlTab(mimTab); setControlTab(mcbiTab); createActions(); initializeToolBar(); initializeMenu(); hookListeners(); if(LogWriter.isEmptyProjectTypes()) LogWriter.initProjectTypes(); }
/** * Initialize the editor */ 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()); // setContentDescription(path.toString()); if (model.isSnapshot()) { final String date = sdf.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); }
protected IWorkbenchPart getActivePart() { IWorkbenchWindow window = getSite().getWorkbenchWindow(); IPartService service = window.getPartService(); IWorkbenchPart part = service.getActivePart(); return part; }
private IWorkbenchPart getActivePart() { IWorkbenchWindow window = getSite().getWorkbenchWindow(); IPartService service = window.getPartService(); IWorkbenchPart part = service.getActivePart(); return part; }
protected void pageChange(final int newPageIndex, final int oldPageIndex) { getActiveEditor(); deactivateSite(false, false); IPartService partService = (IPartService) getSite().getService(IPartService.class); if (partService.getActivePart() == this) { setFocus(); } IEditorPart activeEditor = getEditor(newPageIndex); IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); if (contributor != null && contributor instanceof MultiPageEditorActionBarContributor) { ((MultiPageEditorActionBarContributor) contributor).setActivePage(activeEditor); } if (activeEditor != null) { ISelectionProvider selectionProvider = activeEditor.getSite().getSelectionProvider(); if (selectionProvider != null) { ISelectionProvider outerProvider = getSite().getSelectionProvider(); if (outerProvider instanceof MultiPageToolbarSelectionProvider) { SelectionChangedEvent event = new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection()); MultiPageToolbarSelectionProvider provider = (MultiPageToolbarSelectionProvider) outerProvider; provider.fireSelectionChanged(event); provider.firePostSelectionChanged(event); } else { if (Policy.DEBUG_MPE) { Tracing.printTrace(TRACING_COMPONENT, "MultiPageEditorPart " + getTitle() //$NON-NLS-1$ + " did not propogate selection for " //$NON-NLS-1$ + activeEditor.getTitle()); } } } } activateSite(); postPageChange(newPageIndex, oldPageIndex); Object selectedPage = getSelectedPage(); if (selectedPage != null) { firePageChanged(new PageChangedEvent(this, selectedPage)); } }
public PlanEditorContributionItem(IPartService partService) { this.partService = partService; }
private IWorkbenchPart getActivePart() { IWorkbenchWindow window= getSite().getWorkbenchWindow(); IPartService service= window.getPartService(); IWorkbenchPart part= service.getActivePart(); return part; }
/** * * @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; } }
public static IWorkbenchPart getActivePart(IWorkbenchPartSite site) { IWorkbenchWindow window = site.getWorkbenchWindow(); IPartService service = window.getPartService(); return service.getActivePart(); }
/** * Instantiates a new r zoom combo contribution item. * * @param partService * the part service */ public RZoomComboContributionItem(IPartService partService) { super(partService); }
/** * Constructor for ComboToolItem. * * @param partService * used to add a PartListener */ public ZoomComboContributionItem(IPartService partService) { this(partService, "8888%");//$NON-NLS-1$ }
/** * Constructor for ComboToolItem. * * @param partService * used to add a PartListener * @param initString * the initial string displayed in the combo */ public ZoomComboContributionItem(IPartService partService, String initString) { this(partService, new String[] { initString }); }