org.eclipse.ui.model.IWorkbenchAdapter Java Examples
The following examples show how to use
org.eclipse.ui.model.IWorkbenchAdapter.
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: SVNAdapterFactory.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Method declared on IAdapterFactory. * Get the given adapter for the given object */ public Object getAdapter(Object adaptableObject, Class adapterType) { if (IWorkbenchAdapter.class == adapterType) { return getWorkbenchAdapter(adaptableObject); } if(IDeferredWorkbenchAdapter.class == adapterType) { Object o = getWorkbenchAdapter(adaptableObject); if(o != null && o instanceof IDeferredWorkbenchAdapter) { return o; } return null; } if (IPropertySource.class == adapterType) { return getPropertySource(adaptableObject); } if(IHistoryPageSource.class == adapterType) { return pageHistoryParticipant; } return null; }
Example #2
Source File: ProjectExplorer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * The superclass does not deal with the content description, handle it * here. * * @noreference */ public void updateTitle() { super.updateTitle(); Object input = getCommonViewer().getInput(); if (input == null || input instanceof IAggregateWorkingSet) { setContentDescription(""); //$NON-NLS-1$ return; } if (!(input instanceof IResource)) { if (input instanceof IAdaptable) { IWorkbenchAdapter wbadapter = (IWorkbenchAdapter) ((IAdaptable) input) .getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { setContentDescription(wbadapter.getLabel(input)); return; } } setContentDescription(input.toString()); return; } IResource res = (IResource) input; setContentDescription(res.getName()); }
Example #3
Source File: CordovaPluginAdapterFactory.java From thym with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object getAdapter(Object adaptableObject, Class adapterType) { if(!(adaptableObject instanceof HybridPluginFolder)) return null; HybridPluginFolder pluginFolder = (HybridPluginFolder)adaptableObject; if(IPropertySource.class.equals(adapterType)){ return new CordovaPluginProperties(pluginFolder); } if(IWorkbenchAdapter.class.equals(adapterType)){ return new CordovaPluginWorkbenchAdapter(); } if(IResource.class.equals(adapterType)){ return pluginFolder.getFolder(); } return null; }
Example #4
Source File: CordovaPlatformAdapterFactory.java From thym with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object getAdapter(Object adaptableObject, Class adapterType) { if(!(adaptableObject instanceof HybridPlatformFolder)) return null; HybridPlatformFolder platform = (HybridPlatformFolder)adaptableObject; if(IPropertySource.class.equals(adapterType)){ return new CordovaPlatformProperties(platform); } if(IWorkbenchAdapter.class.equals(adapterType)){ return new CordovaPlatformWorkbenchAdapter(); } if(IResource.class.equals(adapterType)){ return platform.getFolder(); } return null; }
Example #5
Source File: SvnWizardConfigureTagsPage.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public Object[] getChildren(Object parentElement) { if (parentElement instanceof ISVNLocalResource) { Object[] rootChildren = new Object[3]; rootChildren[0] = ((ISVNLocalResource)parentElement).getRepository(); rootChildren[1] = branches; rootChildren[2] = tags; return rootChildren; } if (parentElement instanceof Branches) return ((Branches)parentElement).getBranches(); if (parentElement instanceof Tags) return ((Tags)parentElement).getTags(); IWorkbenchAdapter adapter = getAdapter(parentElement); if (adapter instanceof SVNModelElement) { Object[] children = ((SVNModelElement)adapter).getChildren(parentElement); ArrayList folderArray = new ArrayList(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof ISVNRemoteFolder) folderArray.add(children[i]); } children = new Object[folderArray.size()]; folderArray.toArray(children); return children; } return super.getChildren(parentElement); }
Example #6
Source File: NodeDisplayTableControl.java From depan with Apache License 2.0 | 6 votes |
@Override public String getColumnText(Object element, int columnIndex) { GraphNode node = getGraphNode(element); if (null != node) { switch (columnIndex) { case INDEX_NAME: return node.toString(); case INDEX_XPOS: return getXPos(node); case INDEX_YPOS: return getYPos(node); case INDEX_COLOR: return getColorName(node); case INDEX_SIZE: return getSizeName(node); } } IWorkbenchAdapter item = getWorkbenchAdapter(element); if (null != item) { switch (columnIndex) { case INDEX_NAME: return item.getLabel(element); } } return null; }
Example #7
Source File: ProjectExplorer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * The superclass does not deal with the content description, handle it * here. * * @noreference */ public void updateTitle() { super.updateTitle(); Object input = getCommonViewer().getInput(); if (input == null || input instanceof IAggregateWorkingSet) { setContentDescription(""); //$NON-NLS-1$ return; } if (!(input instanceof IResource)) { if (input instanceof IAdaptable) { IWorkbenchAdapter wbadapter = (IWorkbenchAdapter) ((IAdaptable) input) .getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { setContentDescription(wbadapter.getLabel(input)); return; } } setContentDescription(input.toString()); return; } IResource res = (IResource) input; setContentDescription(res.getName()); }
Example #8
Source File: JavaSearchPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private SearchPatternData tryStructuredSelection(IStructuredSelection selection) { if (selection == null || selection.size() > 1) return null; Object o= selection.getFirstElement(); SearchPatternData res= null; if (o instanceof IJavaElement) { res= determineInitValuesFrom((IJavaElement) o); } else if (o instanceof LogicalPackage) { LogicalPackage lp= (LogicalPackage)o; return new SearchPatternData(PACKAGE, REFERENCES, 0, fIsCaseSensitive, lp.getElementName(), null, getLastIncludeMask()); } else if (o instanceof IAdaptable) { IJavaElement element= (IJavaElement) ((IAdaptable) o).getAdapter(IJavaElement.class); if (element != null) { res= determineInitValuesFrom(element); } } if (res == null && o instanceof IAdaptable) { IWorkbenchAdapter adapter= (IWorkbenchAdapter)((IAdaptable)o).getAdapter(IWorkbenchAdapter.class); if (adapter != null) { return new SearchPatternData(TYPE, REFERENCES, 0, fIsCaseSensitive, adapter.getLabel(o), null, getLastIncludeMask()); } } return res; }
Example #9
Source File: PropertyKeyHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void open(KeyReference keyReference) { if (keyReference == null) return; try { IEditorPart part= keyReference.element != null ? EditorUtility.openInEditor(keyReference.element, true) : EditorUtility.openInEditor(keyReference.resource, true); if (part != null) EditorUtility.revealInEditor(part, keyReference.offset, keyReference.length); } catch (PartInitException x) { String message= null; IWorkbenchAdapter wbAdapter= (IWorkbenchAdapter)((IAdaptable)keyReference).getAdapter(IWorkbenchAdapter.class); if (wbAdapter != null) message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_messageArgs, new String[] { wbAdapter.getLabel(keyReference), x.getLocalizedMessage() } ); if (message == null) message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_message, x.getLocalizedMessage()); MessageDialog.openError(fShell, PropertiesFileEditorMessages.OpenAction_error_messageProblems, message); } }
Example #10
Source File: NodeDisplayTableControl.java From depan with Apache License 2.0 | 6 votes |
@Override public Image getColumnImage(Object element, int columnIndex) { GraphNode node = getGraphNode(element); if (null != node) { switch (columnIndex) { case INDEX_SELECTED: return PlatformResources.getOnOff(isNodeSelected(node)); case INDEX_VISIBLE: return PlatformResources.getOnOff(isVisible(node)); } } IWorkbenchAdapter item = getWorkbenchAdapter(element); if (null != item) { switch (columnIndex) { case INDEX_NAME: return null; // TODO: versus - item.getImageDescriptor(element)... } } // Fall through and unknown type return null; }
Example #11
Source File: CopiedWorkbenchLabelProvider.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override public Image getImage(Object element) { //obtain the base image by querying the element IWorkbenchAdapter adapter = getAdapter(element); if (adapter == null) { return null; } ImageDescriptor descriptor = adapter.getImageDescriptor(element); if (descriptor == null) { return null; } //add any annotations to the image descriptor descriptor = decorateImage(descriptor, element); try { return resourceManager.createImage(descriptor); } catch (Exception e) { Log.log(e); return null; } }
Example #12
Source File: JavaElementComparator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String getNonJavaElementLabel(Viewer viewer, Object element) { // try to use the workbench adapter for non - java resources or if not available, use the viewers label provider if (element instanceof IResource) { return ((IResource) element).getName(); } if (element instanceof IStorage) { return ((IStorage) element).getName(); } if (element instanceof IAdaptable) { IWorkbenchAdapter adapter= (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class); if (adapter != null) { return adapter.getLabel(element); } } if (viewer instanceof ContentViewer) { IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider(); if (prov instanceof ILabelProvider) { return ((ILabelProvider) prov).getText(element); } } return null; }
Example #13
Source File: NodeStatsTableControl.java From depan with Apache License 2.0 | 6 votes |
@Override public Image getColumnImage(Object element, int columnIndex) { GraphNode node = getGraphNode(element); if (null != node) { switch (columnIndex) { case INDEX_ROOT: return PlatformResources.getOnOff(isRoot(node)); } } IWorkbenchAdapter item = getWorkbenchAdapter(element); if (null != item) { switch (columnIndex) { case INDEX_NAME: return null; // TODO: versus - item.getImageDescriptor(element)... } } // Fall through and unknown type return null; }
Example #14
Source File: NodeStatsTableControl.java From depan with Apache License 2.0 | 6 votes |
@Override public String getColumnText(Object element, int columnIndex) { GraphNode node = getGraphNode(element); if (null != node) { switch (columnIndex) { case INDEX_NAME: return node.toString(); case INDEX_RANK: return getRank(node); case INDEX_PREDS: return getPredecessorCount(node); case INDEX_SUCCS: return getSuccessorCount(node); } } IWorkbenchAdapter item = getWorkbenchAdapter(element); if (null != item) { switch (columnIndex) { case INDEX_NAME: return item.getLabel(element); } } return null; }
Example #15
Source File: JavaElementLabels.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the styled label of the given object. The object must be of type {@link IJavaElement} or adapt to {@link IWorkbenchAdapter}. * If the element type is not known, the empty string is returned. * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}. * * @param obj object to get the label for * @param flags the rendering flags * @return the label or the empty string if the object type is not supported * * @since 3.4 */ public static StyledString getStyledTextLabel(Object obj, long flags) { if (obj instanceof IJavaElement) { return getStyledElementLabel((IJavaElement) obj, flags); } else if (obj instanceof IResource) { return getStyledResourceLabel((IResource) obj); } else if (obj instanceof ClassPathContainer) { ClassPathContainer container= (ClassPathContainer) obj; return getStyledContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject()); } else if (obj instanceof IStorage) { return getStyledStorageLabel((IStorage) obj); } else if (obj instanceof IAdaptable) { IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { return Strings.markLTR(new StyledString(wbadapter.getLabel(obj))); } } return new StyledString(); }
Example #16
Source File: TmfProjectModelElement.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public <T> @Nullable T getAdapter(Class<T> adapter) { if (adapter.getClass().isInstance(this)) { return (T)this; } if (IWorkbenchAdapter.class.isAssignableFrom(adapter)) { return ((@Nullable T) new WorkbenchAdapter() { @Override public String getLabel(Object object) { return ((TmfProjectModelElement)object).getName(); } }); } return null; }
Example #17
Source File: AdapterFactory.java From tlaplus with MIT License | 6 votes |
@SuppressWarnings("unchecked") public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType == IWorkbenchAdapter.class) { if (adaptableObject instanceof Spec) { return (T) new SpecWorkbenchAdapter(); } } if (IResource.class.equals(adapterType) && adaptableObject instanceof Module) { return (T) ((Module) adaptableObject).getResource(); } if (IResource.class.equals(adapterType) && adaptableObject instanceof Spec) { return (T) ((Spec) adaptableObject).getRootFile(); } return null; }
Example #18
Source File: XdsElementAdapterFactory.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
@Override public Object getAdapter(Object element, @SuppressWarnings("rawtypes") Class key) { IXdsElement e = (IXdsElement)element; if (IResource.class.isAssignableFrom(key)) { return XdsElementUtils.adaptToResource(e, key); } if (IPropertySource.class.equals(key)) { return getProperties(XdsElementUtils.adaptToResource(e, IResource.class)); } else if (IWorkbenchAdapter.class.equals(key)) { if (xdsWorkbenchAdapter == null) { xdsWorkbenchAdapter = new XdsWorkbenchAdapter(); } return xdsWorkbenchAdapter; } else if (IContributorResourceAdapter.class.equals(key)) { return this; } return null; }
Example #19
Source File: CopiedWorkbenchLabelProvider.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public String getText(Object element) { //query the element for its label IWorkbenchAdapter adapter = getAdapter(element); if (adapter == null) { return ""; //$NON-NLS-1$ } String label = adapter.getLabel(element); //return the decorated label return decorateText(label, element); }
Example #20
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns an image descriptor for a IAdaptable. The descriptor includes overlays, if specified (only error ticks apply). * Returns <code>null</code> if no image could be found. * @param adaptable the adaptable * @param flags the image flags * @return returns the image descriptor */ public ImageDescriptor getWorkbenchImageDescriptor(IAdaptable adaptable, int flags) { IWorkbenchAdapter wbAdapter= (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); if (wbAdapter == null) { return null; } ImageDescriptor descriptor= wbAdapter.getImageDescriptor(adaptable); if (descriptor == null) { return null; } Point size= useSmallSize(flags) ? SMALL_SIZE : BIG_SIZE; return new JavaElementImageDescriptor(descriptor, 0, size); }
Example #21
Source File: WorkspaceRootStub.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> T getAdapter(Class<T> adapter) { if (adapter == IWorkbenchAdapter.class) { return (T) this; } throw new RuntimeException("Not implemented for: " + adapter); }
Example #22
Source File: WrappedResource.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public static <T> T getAdapterFromActualObject(IResource actualObject2, Class<T> adapter) { if (IDeferredWorkbenchAdapter.class.equals(adapter) || IWorkbenchAdapter2.class.equals(adapter) || IWorkbenchAdapter.class.equals(adapter)) { return null; } return actualObject2.getAdapter(adapter); }
Example #23
Source File: ProjectStub.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> T getAdapter(Class<T> adapter) { if (adapter == IWorkbenchAdapter.class) { return (T) this; } throw new RuntimeException("Not impl"); }
Example #24
Source File: PythonBreakpointPage.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Returns the name of the given element. * * @param element * the element * @return the name of the element */ private String getName(IAdaptable element) { IWorkbenchAdapter adapter = element.getAdapter(IWorkbenchAdapter.class); if (adapter != null) { return adapter.getLabel(element); } return "";//$NON-NLS-1$ }
Example #25
Source File: NamePatternFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (fMatchers.length == 0) { return true; } String matchName= null; if (element instanceof IJavaElement) { matchName= ((IJavaElement) element).getElementName(); } else if (element instanceof IResource) { matchName= ((IResource) element).getName(); } else if (element instanceof IStorage) { matchName= ((IStorage) element).getName(); } else if (element instanceof IWorkingSet) { matchName= ((IWorkingSet) element).getLabel(); } else if (element instanceof IAdaptable) { IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)element).getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { matchName= wbadapter.getLabel(element); } } if (matchName != null && matchName.length() > 0) { StringMatcher[] testMatchers= getMatchers(); for (int i = 0; i < testMatchers.length; i++) { if (testMatchers[i].match(matchName)) return false; } return true; } return true; }
Example #26
Source File: StatusBarUpdater.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected String formatMessage(ISelection sel) { if (sel instanceof IStructuredSelection && !sel.isEmpty()) { IStructuredSelection selection= (IStructuredSelection) sel; int nElements= selection.size(); if (nElements > 1) { return Messages.format(JavaUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements)); } else { Object elem= selection.getFirstElement(); if (elem instanceof IJavaElement) { return formatJavaElementMessage((IJavaElement) elem); } else if (elem instanceof IResource) { return formatResourceMessage((IResource) elem); } else if (elem instanceof PackageFragmentRootContainer) { PackageFragmentRootContainer container= (PackageFragmentRootContainer) elem; return container.getLabel() + JavaElementLabels.CONCAT_STRING + container.getJavaProject().getElementName(); } else if (elem instanceof IJarEntryResource) { IJarEntryResource jarEntryResource= (IJarEntryResource) elem; StringBuffer buf= new StringBuffer(BasicElementLabels.getResourceName(jarEntryResource.getName())); buf.append(JavaElementLabels.CONCAT_STRING); IPath fullPath= jarEntryResource.getFullPath(); if (fullPath.segmentCount() > 1) { buf.append(BasicElementLabels.getPathLabel(fullPath.removeLastSegments(1), false)); buf.append(JavaElementLabels.CONCAT_STRING); } buf.append(JavaElementLabels.getElementLabel(jarEntryResource.getPackageFragmentRoot(), JavaElementLabels.ROOT_POST_QUALIFIED)); return buf.toString(); } else if (elem instanceof IAdaptable) { IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)elem).getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { return wbadapter.getLabel(elem); } } } } return ""; //$NON-NLS-1$ }
Example #27
Source File: JavaElementLabels.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the label of the given object. The object must be of type {@link IJavaElement} or adapt to {@link IWorkbenchAdapter}. * If the element type is not known, the empty string is returned. * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}. * * @param obj object to get the label for * @param flags the rendering flags * @return the label or the empty string if the object type is not supported */ public static String getTextLabel(Object obj, long flags) { if (obj instanceof IJavaElement) { return getElementLabel((IJavaElement) obj, flags); } else if (obj instanceof IResource) { return BasicElementLabels.getResourceName((IResource) obj); } else if (obj instanceof ClassPathContainer) { ClassPathContainer container= (ClassPathContainer) obj; IPath containerPath= container.getClasspathEntry().getPath(); try { return getContainerEntryLabel(containerPath, container.getJavaProject()); } catch (JavaModelException e) { return BasicElementLabels.getPathLabel(containerPath, false); } } else if (obj instanceof IStorage) { return BasicElementLabels.getResourceName(((IStorage) obj).getName()); } else if (obj instanceof IAdaptable) { IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { return Strings.markLTR(wbadapter.getLabel(obj)); } } return ""; //$NON-NLS-1$ }
Example #28
Source File: PropertyKeyHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Object getAdapter(Class adapter) { if (adapter == IWorkbenchAdapter.class) return this; else return super.getAdapter(adapter); }
Example #29
Source File: JavaElementAdapterFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Object getAdapter(Object element, Class key) { updateLazyLoadedAdapters(); IJavaElement java= getJavaElement(element); if (IPropertySource.class.equals(key)) { return getProperties(java); } if (IResource.class.equals(key)) { return getResource(java); } if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key)) { return fSearchPageScoreComputer; } if (IWorkbenchAdapter.class.equals(key)) { return getJavaWorkbenchAdapter(); } if (IResourceLocator.class.equals(key)) { return getResourceLocator(); } if (IPersistableElement.class.equals(key)) { return new PersistableJavaElementFactory(java); } if (IContributorResourceAdapter.class.equals(key)) { return this; } if (IContributorResourceAdapter2.class.equals(key)) { return this; } if (ITaskListResourceAdapter.class.equals(key)) { return getTaskListAdapter(); } if (IContainmentAdapter.class.equals(key)) { return getJavaElementContainmentAdapter(); } if (fIsTeamUILoaded && IHistoryPageSource.class.equals(key) && JavaElementHistoryPageSource.hasEdition(java)) { return JavaElementHistoryPageSource.getInstance(); } return null; }
Example #30
Source File: MethodWrapper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Object getAdapter(Class adapter) { if (adapter == IJavaElement.class) { return getMember(); } else if (adapter == IWorkbenchAdapter.class){ return new MethodWrapperWorkbenchAdapter(this); } else { return null; } }