org.eclipse.core.runtime.IAdaptable Java Examples

The following examples show how to use org.eclipse.core.runtime.IAdaptable. 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: N4JSProjectExplorerContentProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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 #2
Source File: CrossflowModelingAssistantProviderOfWorkflowEditPart.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @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 #3
Source File: CrossflowModelingAssistantProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @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 #4
Source File: ConnectionDiscovererBean.java    From neoscada with 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
Source File: ProjectTypeAwareWorkingSetManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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 #6
Source File: CrossflowNavigatorActionProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @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 #7
Source File: CrossflowNavigatorLabelProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @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 #8
Source File: OpenDiagramEditPolicy.java    From scava with 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
Source File: CrossflowViewProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @generated
 */
private IElementType getSemanticElementType(IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	return (IElementType) semanticAdapter.getAdapter(IElementType.class);
}
 
Example #10
Source File: CrossflowModelingAssistantProviderOfTaskEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
@Override

public List<IElementType> getTypesForSource(IAdaptable target, IElementType relationshipType) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForSource((TaskEditPart) targetEditPart, relationshipType);
}
 
Example #11
Source File: WorkflowCanonicalEditPolicy.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private Collection<IAdaptable> createConnections(Collection<CrossflowLinkDescriptor> linkDescriptors,
		Domain2Notation domain2NotationMap) {
	LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>();
	for (CrossflowLinkDescriptor nextLinkDescriptor : linkDescriptors) {
		EditPart sourceEditPart = getSourceEditPart(nextLinkDescriptor, domain2NotationMap);
		EditPart targetEditPart = getTargetEditPart(nextLinkDescriptor, domain2NotationMap);
		if (sourceEditPart == null || targetEditPart == null) {
			continue;
		}
		CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
				nextLinkDescriptor.getSemanticAdapter(),
				CrossflowVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), ViewUtil.APPEND, false,
				((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
		CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
		ccr.setType(RequestConstants.REQ_CONNECTION_START);
		ccr.setSourceEditPart(sourceEditPart);
		sourceEditPart.getCommand(ccr);
		ccr.setTargetEditPart(targetEditPart);
		ccr.setType(RequestConstants.REQ_CONNECTION_END);
		Command cmd = targetEditPart.getCommand(ccr);
		if (cmd != null && cmd.canExecute()) {
			executeCommand(cmd);
			IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
			if (viewAdapter != null) {
				adapters.add(viewAdapter);
			}
		}
	}
	return adapters;
}
 
Example #12
Source File: ParameterCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	Parameter newElement = CrossflowFactory.eINSTANCE.createParameter();

	Language owner = (Language) getElementToEdit();
	owner.getParameters().add(newElement);

	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}
 
Example #13
Source File: CsvSourceCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(CsvSource newElement, IProgressMonitor monitor, IAdaptable info)
		throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #14
Source File: RustLaunchDelegateTools.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the first resource from a structured selection
 *
 * @param selection
 * @return First element in the selection or null if nothing is selected
 */
public static IResource firstResourceFromSelection(ISelection selection) {
	if (selection instanceof IStructuredSelection) {
		Iterator<?> selectionIterator = ((IStructuredSelection) selection).iterator();
		while (selectionIterator.hasNext()) {
			Object element = selectionIterator.next();
			if (element instanceof IResource) {
				return (IResource) element;
			} else if (element instanceof IAdaptable) {
				return ((IAdaptable) element).getAdapter(IResource.class);
			}
		}
	}
	return null;
}
 
Example #15
Source File: ParameterCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(Parameter newElement, IProgressMonitor monitor, IAdaptable info)
		throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #16
Source File: CrossflowModelingAssistantProviderOfCsvSourceEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
@Override

public List<IElementType> getTypesForSource(IAdaptable target, IElementType relationshipType) {
	IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target.getAdapter(IGraphicalEditPart.class);
	return doGetTypesForSource((CsvSourceEditPart) targetEditPart, relationshipType);
}
 
Example #17
Source File: WorkflowCanonicalEditPolicy.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private Collection<IAdaptable> refreshConnections() {
	Domain2Notation domain2NotationMap = new Domain2Notation();
	Collection<CrossflowLinkDescriptor> linkDescriptors = collectAllLinks(getDiagram(), domain2NotationMap);
	Collection existingLinks = new LinkedList(getDiagram().getEdges());
	for (Iterator linksIterator = existingLinks.iterator(); linksIterator.hasNext();) {
		Edge nextDiagramLink = (Edge) linksIterator.next();
		int diagramLinkVisualID = CrossflowVisualIDRegistry.getVisualID(nextDiagramLink);
		if (diagramLinkVisualID == -1) {
			if (nextDiagramLink.getSource() != null && nextDiagramLink.getTarget() != null) {
				linksIterator.remove();
			}
			continue;
		}
		EObject diagramLinkObject = nextDiagramLink.getElement();
		EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
		EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
		for (Iterator<CrossflowLinkDescriptor> linkDescriptorsIterator = linkDescriptors
				.iterator(); linkDescriptorsIterator.hasNext();) {
			CrossflowLinkDescriptor nextLinkDescriptor = linkDescriptorsIterator.next();
			if (diagramLinkObject == nextLinkDescriptor.getModelElement()
					&& diagramLinkSrc == nextLinkDescriptor.getSource()
					&& diagramLinkDst == nextLinkDescriptor.getDestination()
					&& diagramLinkVisualID == nextLinkDescriptor.getVisualID()) {
				linksIterator.remove();
				linkDescriptorsIterator.remove();
				break;
			}
		}
	}
	deleteViews(existingLinks.iterator());
	return createConnections(linkDescriptors, domain2NotationMap);
}
 
Example #18
Source File: CrossflowModelingAssistantProviderOfSourceEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @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((SourceEditPart) sourceEditPart, targetEditPart);
}
 
Example #19
Source File: CsvSinkCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(CsvSink newElement, IProgressMonitor monitor, IAdaptable info)
		throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #20
Source File: CsvSinkCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	CsvSink newElement = CrossflowFactory.eINSTANCE.createCsvSink();

	Workflow owner = (Workflow) getElementToEdit();
	owner.getTasks().add(newElement);

	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}
 
Example #21
Source File: QueueCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(Queue newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #22
Source File: LanguageCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	Language newElement = CrossflowFactory.eINSTANCE.createLanguage();

	Workflow owner = (Workflow) getElementToEdit();
	owner.getLanguages().add(newElement);

	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}
 
Example #23
Source File: TypeExtendingCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	if (!canExecute()) {
		throw new ExecutionException("Invalid arguments in create link command"); //$NON-NLS-1$
	}

	if (getSource() != null && getTarget() != null) {
		getSource().getExtending().add(getTarget());
	}
	return CommandResult.newOKCommandResult();

}
 
Example #24
Source File: CrossflowModelingAssistantProviderOfTypeEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @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((TypeEditPart) sourceEditPart, targetEditPart);
}
 
Example #25
Source File: SourceCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	Source newElement = CrossflowFactory.eINSTANCE.createSource();

	Workflow owner = (Workflow) getElementToEdit();
	owner.getTasks().add(newElement);

	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}
 
Example #26
Source File: Field2CreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(Field newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #27
Source File: CrossflowModelingAssistantProviderOfCsvSourceEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
@Override

public List<IElementType> getRelTypesOnSource(IAdaptable source) {
	IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class);
	return doGetRelTypesOnSource((CsvSourceEditPart) sourceEditPart);
}
 
Example #28
Source File: OpinionatedTaskCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void doConfigure(OpinionatedTask newElement, IProgressMonitor monitor, IAdaptable info)
		throws ExecutionException {
	IElementType elementType = ((CreateElementRequest) getRequest()).getElementType();
	ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
	configureRequest.setClientContext(((CreateElementRequest) getRequest()).getClientContext());
	configureRequest.addParameters(getRequest().getParameters());
	ICommand configureCommand = elementType.getEditCommand(configureRequest);
	if (configureCommand != null && configureCommand.canExecute()) {
		configureCommand.execute(monitor, info);
	}
}
 
Example #29
Source File: OpinionatedTaskCreateCommand.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	OpinionatedTask newElement = CrossflowFactory.eINSTANCE.createOpinionatedTask();

	Workflow owner = (Workflow) getElementToEdit();
	owner.getTasks().add(newElement);

	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}
 
Example #30
Source File: CrossflowViewProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private EObject getSemanticElement(IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
	if (eObject != null) {
		return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
	}
	return null;
}