Java Code Examples for org.eclipse.ui.IWorkbenchPart#getAdapter()
The following examples show how to use
org.eclipse.ui.IWorkbenchPart#getAdapter() .
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: ToggleBreakpointAdapter.java From typescript.java with MIT License | 6 votes |
public void toggleLineBreakpoints(final IWorkbenchPart part, final ISelection selection) throws CoreException { if (!(part instanceof IEditorPart) || !(selection instanceof ITextSelection)) { return; } ITextEditor textEditor = (ITextEditor) part.getAdapter(ITextEditor.class); if (textEditor != null) { IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); if (document != null) { int lineNumber; try { lineNumber = document.getLineOfOffset(((ITextSelection) selection).getOffset()); IResource res = getResource((IEditorPart) part); if (res != null) { addBreakpoint(res, document, lineNumber + 1); } } catch (BadLocationException e) { e.printStackTrace(); } } } }
Example 2
Source File: TabbedPropertySheetTitleProvider.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Constructor for CommonNavigatorTitleProvider. */ public TabbedPropertySheetTitleProvider() { super(); IWorkbenchPart part = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().findView(ProjectExplorer.VIEW_ID); INavigatorContentService contentService = (INavigatorContentService) part .getAdapter(INavigatorContentService.class); if (contentService != null) { labelProvider = contentService.createCommonLabelProvider(); descriptionProvider = contentService .createCommonDescriptionProvider(); } else { WorkbenchNavigatorPlugin.log( "Could not acquire INavigatorContentService from part (\"" //$NON-NLS-1$ + part.getTitle() + "\").", null); //$NON-NLS-1$ } }
Example 3
Source File: TabbedPropertySheetTitleProvider.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Constructor for CommonNavigatorTitleProvider. */ public TabbedPropertySheetTitleProvider() { super(); IWorkbenchPart part = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().findView(ProjectExplorer.VIEW_ID); INavigatorContentService contentService = (INavigatorContentService) part .getAdapter(INavigatorContentService.class); if (contentService != null) { labelProvider = contentService.createCommonLabelProvider(); descriptionProvider = contentService .createCommonDescriptionProvider(); } else { WorkbenchNavigatorPlugin.log( "Could not acquire INavigatorContentService from part (\"" //$NON-NLS-1$ + part.getTitle() + "\").", null); //$NON-NLS-1$ } }
Example 4
Source File: FindBugsAction.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
protected static void refreshViewer(IWorkbenchPart targetPart, final List<WorkItem> resources) { if (targetPart == null) { return; } ISelectionProvider selProvider = (ISelectionProvider) targetPart.getAdapter(ISelectionProvider.class); if (!(selProvider instanceof TreeViewer)) { return; } final TreeViewer viewer = (TreeViewer) selProvider; Display.getDefault().asyncExec(new Runnable() { @Override public void run() { if (viewer.getControl().isDisposed()) { return; } for (WorkItem workItem : resources) { if (workItem.getMarkerTarget() instanceof IProject) { // this element has to be refreshed manually, because // there is no one real // resource associated with it => no resource change // notification after // creating a marker... viewer.refresh(workItem.getCorespondingJavaElement(), true); } } } }); }
Example 5
Source File: EditorActivationTracker.java From typescript.java with MIT License | 5 votes |
public static IDocument getDocument(IWorkbenchPart part) { final IDocument document = (IDocument) part.getAdapter(IDocument.class); if (document != null) { return document; } if (part instanceof ITextEditor) { ITextEditor editor = (ITextEditor) part; return editor.getDocumentProvider().getDocument(editor.getEditorInput()); } return null; }
Example 6
Source File: DynamicDatasetPluginTest.java From dawnsci with Eclipse Public License 1.0 | 5 votes |
/** * Test opens stream in plotting system. * NEED TO Start IOC on ws197 to run this test * @throws Exception */ @Test public void testDynamicDatasetEPICS() throws Exception { // Requires an EPICS stream to connect to, not for general overnight testing! IRemoteDatasetService service = new RemoteDatasetServiceImpl(); IDatasetConnector set = service.createMJPGDataset(new URL("http://ws157.diamond.ac.uk:8080/ADSIM.mjpg.mjpg"), 250, 10); try { set.connect(); IWorkbenchPart part = openView(); final IPlottingSystem<?> sys = (IPlottingSystem<?>)part.getAdapter(IPlottingSystem.class); IImageTrace trace = sys.createImageTrace("MJPG stream"); trace.setDownsampleType(DownsampleType.POINT); // Fast! trace.setRescaleHistogram(false); // Fast! Comes from RGBData anyway though trace.setDynamicData(set); sys.addTrace(trace); TestUtils.delay(10000); } catch (Exception e) { e.printStackTrace(); } finally { set.disconnect(); DynamicConnectionInfo info = set.getDataset().getFirstMetadata(DynamicConnectionInfo.class); System.out.println("Received images = "+info.getReceivedCount()); System.out.println("Dropped images = "+info.getDroppedCount()); } }
Example 7
Source File: ScriptRunToLineAdapter.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param part * @return */ protected ITextEditor getTextEditor( IWorkbenchPart part ) { if ( part instanceof ITextEditor ) { return (ITextEditor) part; } return (ITextEditor) part.getAdapter( ITextEditor.class ); }
Example 8
Source File: AttributeView.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new page in the pagebook for a particular part. This page will * be made visible whenever the part is active, and will be destroyed with a * call to <code>doDestroyPage</code>. * * @param part * the input part * @return the record describing a new page for this view * @see #doDestroyPage */ protected PageRec doCreatePage( IWorkbenchPart part ) { Object page = part.getAdapter( IAttributeViewPage.class ); if ( page instanceof IPageBookViewPage ) { initPage( (IPageBookViewPage) page ); ( (IPageBookViewPage) page ).createControl( getPageBook( ) ); return new PageRec( part, (IPageBookViewPage) page ); } return null; }
Example 9
Source File: CompletionMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * If we are the part deactivated, then time to go * * @param part */ private void checkDeactivation(IWorkbenchPart part) { // getAdapter gets the correct part when dealing with multi-page, otherwise identity if ((IWorkbenchPart) part.getAdapter(ITextEditor.class) == getEditor() || (IWorkbenchPart)getEditor() == part){ leave(true); } }
Example 10
Source File: TabbedPropertySynchronizerListener.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private String activePropertyView(final IWorkbenchPage activePage) { for (final IViewReference ref : activePage.getViewReferences()) { final IWorkbenchPart part = ref.getPart(false); if (part != null && activePage.isPartVisible(part)) { final TabbedPropertySheetPage sheetPage = (TabbedPropertySheetPage) part.getAdapter(TabbedPropertySheetPage.class); if (sheetPage != null) { return ref.getId(); } } } return null; }
Example 11
Source File: ToggleBreakpointAdapter.java From typescript.java with MIT License | 4 votes |
ITextEditor getTextEditor(IWorkbenchPart part) { if (part instanceof ITextEditor) { return (ITextEditor) part; } return (ITextEditor) part.getAdapter(ITextEditor.class); }
Example 12
Source File: BoxProviderImpl.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public boolean supports(final IWorkbenchPart editorPart) { return editorPart.getAdapter(Control.class) instanceof StyledText && (supportsFile(editorPart.getTitle()) || supportsFile(editorPart.getTitleToolTip())); }
Example 13
Source File: KeybindingsManager.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private boolean processKeyStroke(Event event, KeyStroke keyStroke) { IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class); KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence(); KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, keyStroke); if (uniqueKeySequences.contains(sequenceAfterKeyStroke)) { IEvaluationService evaluationService = (IEvaluationService) workbench.getService(IEvaluationService.class); IEvaluationContext evaluationContext = evaluationService.getCurrentState(); IWorkbenchPart workbenchPart = (IWorkbenchPart) evaluationContext.getVariable(ISources.ACTIVE_PART_NAME); ICommandElementsProvider commandElementsProvider = (ICommandElementsProvider) workbenchPart .getAdapter(ICommandElementsProvider.class); if (commandElementsProvider != null) { // Is there a Eclipse binding that matches the key sequence? Binding binding = null; if (bindingService.isPerfectMatch(sequenceAfterKeyStroke)) { // Record it binding = bindingService.getPerfectMatch(sequenceAfterKeyStroke); } List<CommandElement> commandElements = commandElementsProvider .getCommandElements(sequenceAfterKeyStroke); if (commandElements.size() == 0) { if (binding == null) { // Remember the prefix incrementState(sequenceAfterKeyStroke); } else { // Reset our state resetState(); } // Do not consume the event. Let Eclipse handle it. return false; } else { if (binding == null && commandElements.size() == 1) { // We have a unique scripting command to execute executeCommandElement(commandElementsProvider, commandElements.get(0)); // Reset our state resetState(); // The event should be consumed return true; } else { // We need to show commands menu to the user IContextService contextService = (IContextService) workbench.getService(IContextService.class); popup(workbenchPart.getSite().getShell(), bindingService, contextService, commandElementsProvider, commandElements, event, binding, getInitialLocation(commandElementsProvider)); // Reset our state resetState(); // The event should be consumed return true; } } } } else if (uniqueKeySequencesPrefixes.contains(sequenceAfterKeyStroke)) { // Prefix match // Is there a Eclipse command with a perfect match if (bindingService.isPerfectMatch(sequenceAfterKeyStroke)) { // Reset our state resetState(); } else { // Remember the prefix incrementState(sequenceAfterKeyStroke); } } else { // Reset our state resetState(); } // We did not handle the event. Do not consume the event. Let Eclipse handle it. return false; }
Example 14
Source File: DynamicDatasetPluginTest.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
/** * Test opens stream in plotting system. * * Uses the lower level (non-API) objects directly so that we can return after 100 images. * * @throws Exception */ @Test public void testDynamicDataset() throws Exception { SliceClient<BufferedImage> client = new SliceClient<BufferedImage>("localhost", 8080); client.setPath("RANDOM:512x512"); client.setFormat(Format.MJPG); client.setHisto("MEAN"); client.setImageCache(10); // More than we will send... client.setSleep(100); // Default anyway is 100ms final IDynamicMonitorDatasetHolder rgb = DynamicDatasetFactory.createRGBImage(client); // this needs to start before being given to image trace Thread runner = new Thread(new Runnable() { public void run() { try { rgb.start(100); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // blocks until 100 images received. } }); runner.setDaemon(true); runner.setPriority(Thread.MIN_PRIORITY); runner.setName("Test image transfer worker"); runner.start(); IWorkbenchPart part = openView(); final IPlottingSystem<?> sys = (IPlottingSystem<?>)part.getAdapter(IPlottingSystem.class); IImageTrace trace = sys.createImageTrace("RGB stream"); trace.setDynamicData(rgb); sys.addTrace(trace); trace.rehistogram(); TestUtils.delay(20000); // Should easily allow the 100 images to be transfered. DynamicConnectionInfo info = rgb.getDataset().getFirstMetadata(DynamicConnectionInfo.class); long received = info.getReceivedCount(); System.out.println("Received images = "+ received); System.out.println("Dropped images = "+info.getDroppedCount()); if (received<100) throw new Exception("Less than 100 images were received: " + received); }
Example 15
Source File: DynamicDatasetPluginTest.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
/** * Test opens stream in plotting system. * @throws Exception */ @Test public void testHDF5Stream() throws Exception { IWorkbenchPart part = openView(); final IPlottingSystem<?> sys = (IPlottingSystem<?>)part.getAdapter(IPlottingSystem.class); sys.createPlot2D(Random.rand(new int[]{1024, 1024}), null, null); final Collection<ITrace> traces= sys.getTraces(IImageTrace.class); final IImageTrace imt = (IImageTrace)traces.iterator().next(); imt.setDownsampleType(DownsampleType.POINT); // Fast! imt.setRescaleHistogram(false); // Fast! final SliceClient<BufferedImage> client = new SliceClient<BufferedImage>("localhost", 8080); client.setPath("c:/Work/results/TomographyDataSet.hdf5"); client.setDataset("/entry/exchange/data"); client.setSlice("[700,:1024,:1024]"); client.setBin("MEAN:2x2"); client.setFormat(Format.MJPG); client.setHisto("MEDIAN"); client.setImageCache(25); // More than we will send... client.setSleep(100); // Default anyway is 100ms try { int i = 0; while(!client.isFinished()) { final BufferedImage image = client.take(); if (image==null) break; final IDataset set = ServiceHolder.getPlotImageService().createDataset(image); Display.getDefault().syncExec(new Runnable() { public void run() { imt.setData(set, null, false); sys.repaint(); } }); System.out.println("Slice "+i+" plotted"); ++i; TestUtils.delay(100); } } catch (Exception ne) { client.setFinished(true); throw ne; } }
Example 16
Source File: DynamicDatasetPluginTest.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
/** * Test opens stream in plotting system. * @throws Exception */ @Test public void testStreamSpeed() throws Exception { IWorkbenchPart part = openView(); final IPlottingSystem<?> sys = (IPlottingSystem<?>)part.getAdapter(IPlottingSystem.class); sys.createPlot2D(Random.rand(new int[]{1024, 1024}), null, null); final Collection<ITrace> traces= sys.getTraces(IImageTrace.class); final IImageTrace imt = (IImageTrace)traces.iterator().next(); imt.setDownsampleType(DownsampleType.POINT); // Fast! imt.setRescaleHistogram(false); // Fast! final SliceClient<BufferedImage> client = new SliceClient<BufferedImage>("localhost", 8080); client.setPath("RANDOM:1024x1024"); client.setFormat(Format.MJPG); client.setHisto("MEAN"); client.setImageCache(10); // More than we will send... client.setSleep(15); // Default anyway is 100ms try { int i = 0; while(!client.isFinished()) { final BufferedImage image = client.take(); if (image==null) break; final IDataset set = ServiceHolder.getPlotImageService().createDataset(image); Display.getDefault().syncExec(new Runnable() { public void run() { imt.setData(set, null, false); sys.repaint(); } }); System.out.println("Slice "+i+" plotted"); ++i; if (i>100) { client.setFinished(true); break; // That's enough of that } TestUtils.delay(15); } System.out.println("Received images = "+i); System.out.println("Dropped images = "+client.getDroppedImageCount()); } catch (Exception ne) { client.setFinished(true); throw ne; } }