Java Code Examples for org.eclipse.core.runtime.IAdaptable

The following examples show how to use org.eclipse.core.runtime.IAdaptable. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
* @generated
*/
public String getText(Object element) {
	if (element instanceof CrossflowNavigatorGroup) {
		CrossflowNavigatorGroup group = (CrossflowNavigatorGroup) element;
		return group.getGroupName();
	}

	if (element instanceof CrossflowNavigatorItem) {
		CrossflowNavigatorItem navigatorItem = (CrossflowNavigatorItem) element;
		if (!isOwnView(navigatorItem.getView())) {
			return null;
		}
		return getText(navigatorItem.getView());
	}

	// Due to plugin.xml content will be called only for "own" views
	if (element instanceof IAdaptable) {
		View view = (View) ((IAdaptable) element).getAdapter(View.class);
		if (view != null && isOwnView(view)) {
			return getText(view);
		}
	}

	return super.getText(element);
}
 
Example 2
@Override
public Object getParent(Object element) {

	// Required by editor - navigator linking to locate parent item in tree.
	if (element instanceof IProject && workingSetManagerBroker.isWorkingSetTopLevel()) {
		final WorkingSetManager activeManager = workingSetManagerBroker.getActiveManager();
		if (activeManager != null) {
			for (final WorkingSet workingSet : activeManager.getWorkingSets()) {
				final IAdaptable[] elements = workingSet.getElements();
				if (!Arrays2.isEmpty(elements) && Arrays.contains(elements, element)) {
					return workingSet;
				}
			}
		}
	}

	return super.getParent(element);
}
 
Example 3
@Override
public IAdaptable[] getElements() {
	final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	final IProject[] elements = new IProject[projects.length];
	int elementCount = 0;
	for (int i = 0, size = projects.length; i < size; i++) {
		final IProject project = projects[i];
		final IN4JSProject n4Project = core.findProject(toUri(project)).orNull();
		if (type == null) { // Other Projects
			if (n4Project == null || !n4Project.exists()) {
				elements[elementCount++] = project;
			}
		} else {
			if (n4Project != null && n4Project.exists() && type.equals(n4Project.getProjectType())) {
				elements[elementCount++] = project;
			}
		}
	}
	return Arrays.copyOfRange(elements, 0, elementCount);
}
 
Example 4
Source Project: neoscada   Source File: ConnectionDiscovererBean.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public <T> T getAdapter ( final Class<T> adapter )
{
    logger.info ( "Get adaper: {}", adapter );
    if ( adapter == ConnectionDiscoverer.class )
    {
        return adapter.cast ( this.discoverer );
    }
    if ( adapter == ConnectionStore.class && this.discoverer instanceof ConnectionStore )
    {
        return adapter.cast ( this.discoverer );
    }
    if ( this.discoverer instanceof IAdaptable )
    {
        return ( (IAdaptable)this.discoverer ).getAdapter ( adapter );
    }
    return null;
}
 
Example 5
/**
* @generated
*/
@Override

public List<IElementType> getTypesForPopupBar(IAdaptable host) {
	List<IElementType> types = new ArrayList<IElementType>(13);
	types.add(CrossflowElementTypes.CsvSource_2001);
	types.add(CrossflowElementTypes.CsvSink_2002);
	types.add(CrossflowElementTypes.Topic_2003);
	types.add(CrossflowElementTypes.Queue_2004);
	types.add(CrossflowElementTypes.Source_2005);
	types.add(CrossflowElementTypes.Sink_2006);
	types.add(CrossflowElementTypes.CommitmentTask_2007);
	types.add(CrossflowElementTypes.OpinionatedTask_2008);
	types.add(CrossflowElementTypes.ScriptedTask_2015);
	types.add(CrossflowElementTypes.Task_2010);
	types.add(CrossflowElementTypes.Type_2011);
	types.add(CrossflowElementTypes.Field_2014);
	types.add(CrossflowElementTypes.Language_2013);
	return types;
}
 
Example 6
/**
* @generated
*/
protected EObject selectExistingElement(IAdaptable host, Collection types) {
	if (types.isEmpty()) {
		return null;
	}
	IGraphicalEditPart editPart = (IGraphicalEditPart) host.getAdapter(IGraphicalEditPart.class);
	if (editPart == null) {
		return null;
	}
	Diagram diagram = (Diagram) editPart.getRoot().getContents().getModel();
	HashSet<EObject> elements = new HashSet<EObject>();
	for (Iterator<EObject> it = diagram.getElement().eAllContents(); it.hasNext();) {
		EObject element = it.next();
		if (isApplicableElement(element, types)) {
			elements.add(element);
		}
	}
	if (elements.isEmpty()) {
		return null;
	}
	return selectElement((EObject[]) elements.toArray(new EObject[elements.size()]));
}
 
Example 7
/**
* @generated
*/
public final void selectionChanged(IStructuredSelection selection) {
	myDiagram = null;
	if (selection.size() == 1) {
		Object selectedElement = selection.getFirstElement();
		if (selectedElement instanceof CrossflowNavigatorItem) {
			selectedElement = ((CrossflowNavigatorItem) selectedElement).getView();
		} else if (selectedElement instanceof IAdaptable) {
			selectedElement = ((IAdaptable) selectedElement).getAdapter(View.class);
		}
		if (selectedElement instanceof Diagram) {
			Diagram diagram = (Diagram) selectedElement;
			if (WorkflowEditPart.MODEL_ID.equals(CrossflowVisualIDRegistry.getModelID(diagram))) {
				myDiagram = diagram;
			}
		}
	}
	setEnabled(myDiagram != null);
}
 
Example 8
Source Project: scava   Source File: OpenDiagramEditPolicy.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
		throws ExecutionException {
	try {
		Diagram diagram = getDiagramToOpen();
		if (diagram == null) {
			diagram = intializeNewDiagram();
		}
		URI uri = EcoreUtil.getURI(diagram);
		String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
		IEditorInput editorInput = new URIEditorInput(uri, editorName);
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		page.openEditor(editorInput, getEditorID());
		return CommandResult.newOKCommandResult();
	} catch (Exception ex) {
		throw new ExecutionException("Can't open diagram", ex);
	}
}
 
Example 9
@Override
public IAdaptable createElement(IMemento memento) {
	String connectionId = memento.getString(CONNECTION_ID);
	String connectionUri = memento.getString(CONNECTION_URI);
	String connectionName = memento.getString(CONNECTION_NAME);
	String projectId = memento.getString(PROJECT_ID);
	String projectName = memento.getString(PROJECT_NAME);
	return new ApplicationOverviewEditorInput(connectionId, connectionUri, connectionName, projectId, projectName);
}
 
Example 10
/**
* @generated
*/
@Override

public List<IElementType> getTypesForSource(IAdaptable target, IElementType relationshipType) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForSource((TopicEditPart) targetEditPart, relationshipType);
}
 
Example 11
@Override
protected IJavaStackFrame getStackFrame(ITextViewer viewer, ITextEditor textEditor) {
	IAdaptable adaptable = DebugUITools.getPartDebugContext(textEditor.getSite());
	if (adaptable != null) {
		return adaptable.getAdapter(IJavaStackFrame.class);
	}
	return null;
}
 
Example 12
private IEditorInput getRestoredInput(IEditorReference e) {

    IMemento editorMem = null;
    if (CheckstyleUIPlugin.isE3()) {
      editorMem = getMementoE3(e);
    } else {
      editorMem = getMementoE4(e);
    }

    if (editorMem == null) {
      return null;
    }
    IMemento inputMem = editorMem.getChild(IWorkbenchConstants.TAG_INPUT);
    String factoryID = null;
    if (inputMem != null) {
      factoryID = inputMem.getString(IWorkbenchConstants.TAG_FACTORY_ID);
    }
    if (factoryID == null) {
      return null;
    }
    IAdaptable input = null;

    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
    if (factory == null) {
      return null;
    }

    input = factory.createElement(inputMem);
    if (input == null) {
      return null;
    }

    if (!(input instanceof IEditorInput)) {
      return null;
    }
    return (IEditorInput) input;
  }
 
Example 13
/**
* @generated
*/
@Override

public List<IElementType> getTypesForPopupBar(IAdaptable host) {
	List<IElementType> types = new ArrayList<IElementType>(1);
	types.add(CrossflowElementTypes.Field_3003);
	return types;
}
 
Example 14
/**
* @generated
*/
@Override

public List<IElementType> getTypesForSource(IAdaptable target, IElementType relationshipType) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForSource((TypeEditPart) targetEditPart, relationshipType);
}
 
Example 15
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnSourceAndTarget(IAdaptable source, IAdaptable target) {
	IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class);
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnSourceAndTarget((QueueEditPart) sourceEditPart, targetEditPart);
}
 
Example 16
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnTarget(IAdaptable target) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnTarget((SinkEditPart) targetEditPart);
}
 
Example 17
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnTarget(IAdaptable target) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnTarget((TaskEditPart) targetEditPart);
}
 
Example 18
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnTarget(IAdaptable target) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnTarget((CsvSourceEditPart) targetEditPart);
}
 
Example 19
Source Project: n4js   Source File: N4JSProjectActionGroup.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private boolean areOnlyProjectsSelected(final IStructuredSelection selection) {
	if (selection.isEmpty())
		return false;

	final Iterator<?> iter = selection.iterator();
	while (iter.hasNext()) {
		final Object obj = iter.next();
		if (obj instanceof IAdaptable) {
			if (((IAdaptable) obj).getAdapter(IProject.class) == null) {
				return false;
			}
		}
	}
	return true;
}
 
Example 20
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnSource(IAdaptable source) {
	IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnSource((QueueEditPart) sourceEditPart);
}
 
Example 21
Source Project: aCute   Source File: DotnetNewWizard.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Set<IWorkingSet> getWorkingSets(IResource resource) {
	IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets();
	Set<IWorkingSet> fileWorkingSets = new HashSet<>();

	for (IWorkingSet iWorkingSet : allWorkingSets) {
		IAdaptable[] elements = iWorkingSet.getElements();
		if (Arrays.asList(elements).contains(resource.getProject())) {
			fileWorkingSets.add(iWorkingSet);
		}
	}

	return fileWorkingSets;
}
 
Example 22
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnSource(IAdaptable source) {
	IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnSource((CommitmentTaskEditPart) sourceEditPart);
}
 
Example 23
Source Project: aCute   Source File: Tester.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private IResource toResource(Object o) {
	if (o instanceof IResource) {
		return (IResource) o;
	} else if (o instanceof IAdaptable) {
		return ((IAdaptable) o).getAdapter(IResource.class);
	} else {
		return null;
	}
}
 
Example 24
Source Project: neoscada   Source File: AdapterHelper.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adapt an object to the requested target class if possible
 * <p>
 * The following order is tried:
 * <ul>
 * <li>via casting</li>
 * <li>via {@link IAdaptable}</li>
 * <li>via {@link IAdapterManager#getAdapter(Object, Class)} if the
 * parameter
 * <q>load</q> is <code>false</code></li>
 * <li>via {@link IAdapterManager#loadAdapter(Object, String)} if the
 * parameter
 * <q>load</q> is <code>true</code></li>
 * </p>
 * 
 * @param target
 *            the object to convert
 * @param adapterClass
 *            the target class
 * @param load
 *            a flag allowing to control if the adapter manager should also
 *            try loading bundles. See
 *            {@link IAdapterManager#loadAdapter(Object, String)}
 * @return an instance of the target class or <code>null</code> if the
 *         object cannot be adapted to the target class
 */
@SuppressWarnings ( "unchecked" )
public static <T> T adapt ( final Object target, final Class<T> adapterClass, final boolean load )
{
    if ( target == null )
    {
        return null;
    }

    if ( adapterClass.isAssignableFrom ( target.getClass () ) )
    {
        return adapterClass.cast ( target );
    }

    if ( target instanceof IAdaptable )
    {
        return (T) ( (IAdaptable)target ).getAdapter ( adapterClass );
    }

    if ( load )
    {
        return (T)Platform.getAdapterManager ().loadAdapter ( target, adapterClass.getName () );
    }
    else
    {
        return (T)Platform.getAdapterManager ().getAdapter ( target, adapterClass );
    }
}
 
Example 25
/**
* @generated
*/
@Override

public List<IElementType> getTypesForTarget(IAdaptable source, IElementType relationshipType) {
	IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForTarget((TopicEditPart) sourceEditPart, relationshipType);
}
 
Example 26
@Override
public <T> T getAdapter ( final Object adaptableObject, final Class<T> adapterType )
{
    if ( adaptableObject instanceof IAdaptable )
    {
        return ( (IAdaptable)adaptableObject ).getAdapter ( adapterType );
    }
    return null;
}
 
Example 27
@Override
public <T> T getAdapter ( final Object adaptableObject, final Class<T> adapterType )
{
    logger.debug ( "Adapting: {} to {}", adaptableObject, adapterType );

    if ( adaptableObject instanceof ConnectionHolder && adapterType == IPropertySource.class )
    {
        return adapterType.cast ( new PropertySourceWrapper ( (ConnectionHolder)adaptableObject ) );
    }
    if ( adaptableObject instanceof IAdaptable )
    {
        return ( (IAdaptable)adaptableObject ).getAdapter ( adapterType );
    }
    return null;
}
 
Example 28
@Override
@SuppressWarnings ( "rawtypes" )
public Object getAdapter ( final Object adaptableObject, final Class adapterType )
{
    if ( adaptableObject instanceof IAdaptable )
    {
        return ( (IAdaptable)adaptableObject ).getAdapter ( adapterType );
    }
    return null;
}
 
Example 29
/**
* @generated
*/
@Override

public List<IElementType> getTypesForSource(IAdaptable target, IElementType relationshipType) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForSource((SinkEditPart) targetEditPart, relationshipType);
}
 
Example 30
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	for (Iterator it = myDescriptors.iterator(); it.hasNext();) {
		CreateViewRequest.ViewDescriptor nextDescriptor = (CreateViewRequest.ViewDescriptor) it.next();
		View view = (View) nextDescriptor.getAdapter(View.class);
		if (view != null && view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
			EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
			shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
			shortcutAnnotation.getDetails().put("modelID", WorkflowEditPart.MODEL_ID); //$NON-NLS-1$
			view.getEAnnotations().add(shortcutAnnotation);
		}
	}
	return CommandResult.newOKCommandResult();
}