public void hookOnViewer(final String viewerId) { IWorkbench workbench = PlatformUI.getWorkbench(); if (viewerId != null && workbench != null && workbench.getDisplay() != null) { Display display = workbench.getDisplay(); Thread displayThread = display.getThread(); if (workbench.isStarting() || !Thread.currentThread().equals(displayThread)) { // while workbench is starting defer hooking until later UIJob job = new UIJob(display, "viewer hooker") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { hookOnViewer(viewerId); return Status.OK_STATUS; } }; job.schedule(250); } else if (viewerId != null) { CommonNavigator navigator = (CommonNavigator) eu.fittest.eclipse.gui.utils.Viewer.getView(viewerId); if (navigator != null) { CommonViewer viewer = navigator.getCommonViewer(); if (viewer != null) { if (this.viewer != null) { this.viewer.removeSelectionChangedListener(this); } requestRefresh(); viewer.addSelectionChangedListener(this); this.viewer = viewer; } } } } }
/** * Constructs a new instance of <code>BindingService</code> using a JFace binding manager. * * @param bindingManager The bind ing manager to use; must not be <code>null</code>. * @param commandService The command service providing support for this service; must not be * <code>null</code>; * @param workbench The workbench on which this context service will act; must not be <code>null * </code>. */ public BindingService( final BindingManager bindingManager, final ICommandService commandService, final IWorkbench workbench) { if (bindingManager == null) { throw new NullPointerException( "Cannot create a binding service with a null manager"); //$NON-NLS-1$ } if (commandService == null) { throw new NullPointerException( "Cannot create a binding service with a null command service"); //$NON-NLS-1$ } this.bindingManager = bindingManager; this.workbench = workbench; // Hook up the key binding support. this.bindingPersistence = new BindingPersistence(bindingManager, commandService); keyboard = new WorkbenchKeyboard(workbench); final Display display = workbench.getDisplay(); final Listener listener = keyboard.getKeyDownFilter(); display.addFilter(SWT.KeyDown, listener); // RAP [if] Listening for both SWT.KeyDown and SWT.Traverse events execute the command twice // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=381092 // display.addFilter(SWT.Traverse, listener); // ENDRAP // Initialize the key formatter. KeyFormatterFactory.setDefault(SWTKeySupport.getKeyFormatterForPlatform()); }
@Override public void earlyStartup() { IEclipsePreferences pref = ConfigurationScope.INSTANCE.getNode(this.getClass().getName()); if (pref.getBoolean(CFG_SHOW_PERSPECTIVE_KEY, true)) { pref.putBoolean(CFG_SHOW_PERSPECTIVE_KEY, false); try { pref.flush(); } catch (BackingStoreException e) { Activator.error(e); } final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null && window.getActivePage() != null) { IPerspectiveDescriptor desc = PlatformUI.getWorkbench() .getPerspectiveRegistry() .findPerspectiveWithId(TYPESCRIPT_PERSPECTIVE_ID); window.getActivePage().setPerspective(desc); } } }); } }
/** * Construct a new <code>UIAuthTokenProvider</code>. * * @param shell The shell that is used to create wizards and dialogs. */ public UIAuthTokenProvider(final Shell shell) { IWorkbench workbench = PlatformUI.getWorkbench(); this.display = workbench.getDisplay(); this.shell = shell; if (shell == null) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { this.shell = window.getShell(); } } }
/* * (non-Javadoc) * * @see org.eclipse.equinox.app.IApplication#stop() */ public void stop() { final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return; final Display display = workbench.getDisplay(); display.syncExec( new Runnable() { public void run() { if (!display.isDisposed()) workbench.close(); } }); }
public void initialize() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { init(workbench.getActiveWorkbenchWindow()); } }); }
public static boolean openEditor(final UiAutomatorResult r) { final IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(r.uiHierarchy.getAbsolutePath())); if (!fileStore.fetchInfo().exists()) { return false; } final AtomicBoolean status = new AtomicBoolean(false); final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .syncExec( new Runnable() { @Override public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) { return; } IWorkbenchPage page = window.getActivePage(); if (page == null) { return; } // try to switch perspectives if possible if (page.isEditorAreaVisible() == false && InstallDetails.isAdtInstalled()) { try { workbench.showPerspective( "org.eclipse.jdt.ui.JavaPerspective", window); // $NON-NLS-1$ } catch (WorkbenchException e) { } } IEditorPart editor = null; try { editor = IDE.openEditorOnFileStore(page, fileStore); } catch (PartInitException e) { return; } if (!(editor instanceof UiAutomatorViewer)) { return; } ((UiAutomatorViewer) editor).setModel(r.model, r.uiHierarchy, r.screenshot); status.set(true); } }); return status.get(); }
/* * (non-Javadoc) * * @see org.eclipse.equinox.app.IApplication#stop() */ @Override public void stop() { if (!PlatformUI.isWorkbenchRunning()) return; final IWorkbench workbench = PlatformUI.getWorkbench(); final Display display = workbench.getDisplay(); display.syncExec( new Runnable() { @Override public void run() { if (!display.isDisposed()) workbench.close(); } }); }
public final void dispose() { // RAP [rst] safeguard against NPE if (keyboard == null || workbench == null) return; // RAP [rst] move "workbench = null" down to prevent NPE final Listener listener = keyboard.getKeyDownFilter(); final Display display = workbench.getDisplay(); if (display != null) { display.removeFilter(SWT.KeyDown, listener); display.removeFilter(SWT.Traverse, listener); } workbench = null; keyboard = null; bindingPersistence.dispose(); }
private void showStartupDialog() { workbench .getDisplay() .syncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { NewWorkbookEditor.showIn(window); // NewWorkbookWizardDialog.openWizard(window, true); } } }); }
/** Register part listener for editor to install c ast reconcile listener */ private void registerListeners() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { IWorkbenchWindow active = workbench.getActiveWorkbenchWindow(); final IWorkbenchPage page = active.getActivePage(); IPartListener2 partListener = new IPartListener2() { CodanCReconciler reconsiler = new CodanCReconciler(); public void partActivated(IWorkbenchPartReference partRef) {} public void partDeactivated(IWorkbenchPartReference partRef) {} public void partOpened(IWorkbenchPartReference partRef) { IWorkbenchPart editor = partRef.getPart(false); if (editor instanceof ITextEditor) { reconsiler.install((ITextEditor) editor); } } public void partHidden(IWorkbenchPartReference partRef) {} public void partVisible(IWorkbenchPartReference partRef) {} public void partClosed(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part instanceof ITextEditor) { reconsiler.uninstall((ITextEditor) part); } } public void partBroughtToTop(IWorkbenchPartReference partRef) {} public void partInputChanged(IWorkbenchPartReference partRef) {} }; page.addPartListener(partListener); // check current open editors IEditorReference[] editorReferences = page.getEditorReferences(); for (int i = 0; i < editorReferences.length; i++) { IEditorReference ref = editorReferences[i]; partListener.partOpened(ref); } } }); }
protected IStatus run(IProgressMonitor monitor) { monitor.beginTask(null, 3); doStartup(monitor); Display display = workbench.getDisplay(); if (display != null && !display.isDisposed()) { display.asyncExec( new Runnable() { public void run() { System.setProperty( "org.xmind.cathy.app.status", "workbenchReady"); // $NON-NLS-1$ //$NON-NLS-2$ } }); } monitor.done(); return Status.OK_STATUS; }
@Override public void earlyStartup() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { workbench.addWindowListener(listener); for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) for (IWorkbenchPage page : window.getPages()) { page.addPartListener(listener); for (IViewReference part : page.getViewReferences()) { checkPart(part.getView(false)); } } } }); }
/* (non-Javadoc) * @see org.eclipse.ui.IStartup#earlyStartup() */ @Override public void earlyStartup() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { WorkbenchWindowPageListener listener = new WorkbenchWindowPageListener(); window.addPageListener(listener); // If there is already an opened page attach to it IWorkbenchPage page = window.getActivePage(); if (page != null) listener.pageActivated(page); } } }); }
private boolean hasOpenedEditors() { final boolean[] ret = new boolean[1]; ret[0] = false; workbench .getDisplay() .syncExec( new Runnable() { public void run() { for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { IWorkbenchPage page = window.getActivePage(); if (page != null) { if (page.getEditorReferences().length > 0) { ret[0] = true; return; } } } } }); return ret[0]; }
private IEditorPart openEditor(final IEditorInput editorInput) { final IEditorPart[] editor = new IEditorPart[1]; workbench .getDisplay() .syncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { final IWorkbenchPage page = window.getActivePage(); if (page != null) { SafeRunner.run( new SafeRunnable() { public void run() throws Exception { editor[0] = page.openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID); } }); } } } }); return editor[0]; }
/** Notifies the listener that the menu is about to be hidden. */ public final void menuAboutToHide(final IMenuManager mgr) { gatherContributions(mgr); cleanupNeeded = true; // Remove this menu as a visible menu. final IWorkbenchPartSite site = part.getSite(); if (site != null) { final IWorkbench workbench = site.getWorkbenchWindow().getWorkbench(); if (workbench instanceof Workbench) { // try delaying this until after the selection event // has been fired. // This is less threatening if the popup: menu // contributions aren't tied to the evaluation service workbench .getDisplay() .asyncExec( new Runnable() { public void run() { final Workbench realWorkbench = (Workbench) workbench; runCleanUp(realWorkbench); } }); } } }
public void earlyStartup() { IWorkbench workbench = PlatformUI.getWorkbench(); windows = workbench.getWorkbenchWindows(); workbench.getDisplay().asyncExec(this); }
@Override public void draw(MapGraphicContext context) { // Initialize ILayer graticule = context.getLayer(); GraticuleStyle style = GraticuleStyle.getStyle(graticule); // Ensure CRS? if (graticule instanceof Layer) { // Initialize CRS? if (style.isInitCRS()) { // Only initialize once style.setInitCRS(false); // Apply CRS from context GraticuleCRSConfigurator.apply((Layer) graticule, context.getCRS()); } else if (mismatch(graticule, style)) { // Apply CRS from GraticuleCRSConfigurator.apply((Layer) graticule, style.getCRS()); } } // Sanity checks if (MAX_SCALE < context.getMap().getViewportModel().getScaleDenominator()) { graticule.setStatus(ILayer.ERROR); graticule.setStatusMessage(Messages.GraticuleGraphic_Maximum_Scale + MAX_SCALE); return; } Unit<?> unit = CRSUtilities.getUnit(graticule.getCRS().getCoordinateSystem()); if (!SI.METER.equals(unit)) { graticule.setStatus(ILayer.ERROR); graticule.setStatusMessage(Messages.GraticuleGraphic_Illegal_CRS); return; } final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return; // Start working on layer graticule.setStatus(ILayer.WORKING); graticule.setStatusMessage(null); // Get display to work on final Display display = workbench.getDisplay(); // Set styles Font plain = GraticuleStyle.getFontStyle(context).getFont(); Font bold = plain.deriveFont(Font.BOLD); // Initialize the graphics handle ViewportGraphics g = context.getGraphics(); // Set font size g.setFont(bold); // Get bounds of viewport ReferencedEnvelope bounds = context.getViewportModel().getBounds(); try { // Get square size limited to minimum size of 100 pixels double size = size(context, unit, 100); // Sanity check if (size < 100) return; // Convert square size to pixels int sx = (int) (size / context.getViewportModel().getPixelSize().x); int sy = (int) (size / context.getViewportModel().getPixelSize().y); // Make transform from Graticule to map CRS MathTransform transform = CRS.findMathTransform(graticule.getCRS(), context.getCRS(), false); // Transform bounds into Graticule CRS bounds = bounds.transform(graticule.getCRS(), true); // Get squares inside bounds SimpleFeatureIterator it = squares(bounds, size); // Draw one squares at the time (only top and left lines are drawn) while (it.hasNext()) { // Initialize states int i = 0; Point current = null; // Initialize lines List<Line> lines = new ArrayList<Line>(2); List<Label> labels = new ArrayList<Label>(2); // Get next geometry Geometry geom = (Geometry) it.next().getDefaultGeometry(); // Get coordinates in graticule CRS Coordinate[] coords = geom.getCoordinates(); // Get x-coordinate label from upper left corner String tx = getLabel(coords[0].x, size, unit, style); // Get y-coordinate label from lower left corner String ty = getLabel(coords[2].y, size, unit, style); // Insert gap with label? boolean vgap = isGap(tx, unit, style); boolean hgap = isGap(ty, unit, style); // Transform coordinates into Map CRS coords = JTS.transform(geom, transform).getCoordinates(); // Create lines and labels for this square for (Coordinate c : coords) { // Build paths switch (i) { case 1: // ----------------------- // Vertical line // ----------------------- // Create line path current = vert( display, g, sy, style.getLineWidth(), current, context.worldToPixel(c), hgap, vgap, lines); // Add xx label? if (hgap) { labels.add(new Label(current, tx, vgap ? bold : plain)); current = context.worldToPixel(c); } break; case 2: // ----------------------- // Horizontal line // ----------------------- // Create line path current = horz( display, g, sx, style.getLineWidth(), current, context.worldToPixel(c), vgap, hgap, lines); // Add yy label? if (vgap) { labels.add(new Label(current, ty, hgap ? bold : plain)); current = context.worldToPixel(c); } break; default: current = context.worldToPixel(c); break; } i++; } // Draw lines for (Line line : lines) line.draw(g, style); // Draw labels? if (style.isShowLabels()) for (Label label : labels) label.draw(g, style); } // // Get lower left corner coordinates // int x = llc.x; // int y = llc.y; // // // Print borders // g.setColor(lc); // g.setStroke(ViewportGraphics.LINE_SOLID, 5); // // // Inner rectangle // g.drawRect(x + d + l, y + d + l, w - 2 * (d + l), h - 2 * (d + l)); // // // Make white border // g.setColor(Color.WHITE); // // // Left // g.drawRect(x, y, d, h); // g.fillRect(x, y, d, h); // // // Bottom // g.drawRect(x, y, w, d); // g.fillRect(x, y, w, d); // // // Right // g.drawRect(x + w - d, y, d, h); // g.fillRect(x + w - d, y, d, h); // // // Top // g.drawRect(x, y + h - d, w, d); // g.fillRect(x, y + h - d, w, d); } catch (IOException ex) { MapGraphicPlugin.log(Messages.GraticuleGraphic_Error, ex); } catch (FactoryException ex) { MapGraphicPlugin.log(Messages.GraticuleGraphic_Error, ex); } catch (MismatchedDimensionException ex) { MapGraphicPlugin.log(Messages.GraticuleGraphic_Error, ex); } catch (TransformException ex) { MapGraphicPlugin.log(Messages.GraticuleGraphic_Error, ex); } // Finished working on layer graticule.setStatus(ILayer.DONE); }
protected void openStartupMap(IProgressMonitor monitor) { if (!hasOpenedEditors()) { int action = CathyPlugin.getDefault().getPreferenceStore().getInt(CathyPlugin.STARTUP_ACTION); if (action == CathyPlugin.STARTUP_ACTION_HOME) { monitor.subTask(WorkbenchMessages.StartupJob_OpenHomeMap); SafeRunner.run( new SafeRunnable() { public void run() throws Exception { workbench .getDisplay() .syncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { final IWorkbenchPage page = window.getActivePage(); Shell shell = window.getShell(); if (page != null) { OpenHomeMapAction.openHomeMap(shell, page); } } } }); } }); } else if (action == CathyPlugin.STARTUP_ACTION_BLANK) { monitor.subTask(WorkbenchMessages.StartupJob_OpenBlankMap); openBlankMap(); } else if (action == CathyPlugin.STARTUP_ACTION_LAST) { IPath editorStatusPath = WorkbenchPlugin.getDefault() .getDataLocation() .append("XMind_Editors.xml"); // $NON-NLS-1$ // open unclosed editors in the last session. final File stateFile = editorStatusPath.toFile(); if (stateFile.exists()) workbench .getDisplay() .syncExec( new Runnable() { public void run() { SafeRunner.run( new SafeRunnable() { public void run() throws Exception { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { openUnclosedMapLastSession(stateFile, page); } } } }); } }); } if (!hasOpenedEditors()) { showStartupDialog(); } } monitor.worked(1); }
@Override public void earlyStartup() { final IWorkbench workbench = PlatformUI.getWorkbench(); // listen for save file events ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class); executionListener = new CustomExecutionListener(); commandService.addExecutionListener(executionListener); workbench .getDisplay() .asyncExec( new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) return; // setup config file parsing MenuHandler handler = new MenuHandler(); DEBUG = handler.getDebug(); // prompt for apiKey if not set String apiKey = handler.getApiKey(); if (apiKey == "") { handler.promptForApiKey(window); } Dependencies deps = new Dependencies(); if (!deps.isPythonInstalled()) { deps.installPython(); if (!deps.isPythonInstalled()) { MessageDialog dialog = new MessageDialog( window.getShell(), "Warning!", null, "WakaTime needs Python installed. Please install Python from python.org/downloads, then restart Eclipse.", MessageDialog.WARNING, new String[] {IDialogConstants.OK_LABEL}, 0); dialog.open(); } } if (!deps.isCLIInstalled()) { deps.installCLI(); } if (window.getPartService() == null) return; // listen for caret movement if (window.getPartService().getActivePartReference() != null && window.getPartService().getActivePartReference().getPage() != null && window.getPartService().getActivePartReference().getPage().getActiveEditor() != null) { IEditorPart part = window.getPartService().getActivePartReference().getPage().getActiveEditor(); if (!(part instanceof AbstractTextEditor)) return; ((StyledText) part.getAdapter(Control.class)) .addCaretListener(new CustomCaretListener()); } // listen for change of active file window.getPartService().addPartListener(editorListener); if (window.getPartService().getActivePart() == null) return; if (window.getPartService().getActivePart().getSite() == null) return; if (window.getPartService().getActivePart().getSite().getPage() == null) return; if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return; if (window .getPartService() .getActivePart() .getSite() .getPage() .getActiveEditor() .getEditorInput() == null) return; // log file if one is opened by default IEditorInput input = window .getPartService() .getActivePart() .getSite() .getPage() .getActiveEditor() .getEditorInput(); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput) input).getURI(); if (uri != null && uri.getPath() != null) { String currentFile = uri.getPath(); long currentTime = System.currentTimeMillis() / 1000; if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) { WakaTime.logFile(currentFile, WakaTime.getActiveProject(), false); WakaTime.getDefault().lastFile = currentFile; WakaTime.getDefault().lastTime = currentTime; } } } WakaTime.log( "Finished initializing WakaTime plugin (https://wakatime.com) v" + VERSION); } }); }