Java 类org.eclipse.core.runtime.IAdaptable 实例源码
项目:MBSE-Vacation-Manager
文件:ExportHandler.java
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
/*MessageDialog.openInformation(
window.getShell(),
"Plugin",
"Hello, Eclipse world");*/
// Pfad vom Projekt
if (window != null)
{
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable)
{
IProject project = (IProject)((IAdaptable)firstElement).getAdapter(IProject.class);
IPath path = project.getFullPath();
System.out.println("Projekt: "+path);
StartEGL.start(""+path);
}
}
return null;
}
项目:n4js
文件:N4JSProjectExplorerContentProvider.java
@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);
}
项目:n4js
文件:ProjectTypeAwareWorkingSetManager.java
@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);
}
项目:gemoc-studio-modeldebugging
文件:GemocSequentialPropertyTester.java
protected boolean isModel(IAdaptable receiver){
IFile modelFile = (IFile)(receiver).getAdapter(IFile.class);
if(modelFile !=null){
ResourceSet rs = new ResourceSetImpl();
URI modelURI = URI.createURI("platform:/resource/"+modelFile.getFullPath().toString());
try{
Resource resource = rs.getResource(modelURI, true);
if (resource != null) {
return true;
}
} catch (Exception e){
// not a valid model, simply ignore
return false;
}
}
return false;
}
项目:gemoc-studio-modeldebugging
文件:GemocSequentialPropertyTester.java
/**
* Method runs the tests defined from extension points for Run As... and Debug As... menu items.
*
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
* @since 3.2
* @return true if the specified tests pass, false otherwise
*/
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if(PROPERTY_IS_MODEL.equals(property)) {
if (receiver instanceof IAdaptable) {
return isModel((IAdaptable)receiver);
}
return false;
}
if(PROPERTY_IS_EXECUTABLE_DOMAIN_SPECIFIC_MODEL.equals(property)) {
if (receiver instanceof IAdaptable) {
return isExecutableDomainSpecificModel((IAdaptable)receiver);
}
return false;
}
return false;
}
项目:eclipse-batch-editor
文件:BatchSourceViewerConfiguration.java
/**
* Creates configuration by given adaptable
*
* @param adaptable
* must provide {@link ColorManager} and {@link IFile}
*/
public BatchSourceViewerConfiguration(IAdaptable adaptable) {
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
this.fPreferenceStore = new ChainedPreferenceStore(
new IPreferenceStore[] { getPreferences().getPreferenceStore(), generalTextStore });
Assert.isNotNull(adaptable, "adaptable may not be null!");
this.annotationHoover = new BatchEditorAnnotationHoover();
this.contentAssistant = new ContentAssistant();
contentAssistProcessor = new BatchEditorSimpleWordContentAssistProcessor();
contentAssistant.enableColoredLabels(true);
contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
for (BatchDocumentIdentifier identifier: BatchDocumentIdentifiers.values()){
contentAssistant.setContentAssistProcessor(contentAssistProcessor, identifier.getId());
}
contentAssistant.addCompletionListener(contentAssistProcessor.getCompletionListener());
this.colorManager = adaptable.getAdapter(ColorManager.class);
Assert.isNotNull(colorManager, " adaptable must support color manager");
this.defaultTextAttribute = new TextAttribute(
colorManager.getColor(getPreferences().getColor(COLOR_NORMAL_TEXT)));
this.adaptable=adaptable;
}
项目:neoscada
文件:ConnectionDiscovererBean.java
@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;
}
项目:scanning
文件:ExecuteView.java
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!getViewSite().getPage().isPartVisible(this)) return;
if (selection instanceof IStructuredSelection) {
Object ob = ((IStructuredSelection)selection).getFirstElement();
// This slightly funny alg or assign and sometimes update
// is correct. Do not change unless sure that UI is working afterwards.
if (ob instanceof IAdaptable) { // TODO Replace with ScanBuilderService
CompoundModel<IROI> cm = ((IAdaptable)ob).getAdapter(CompoundModel.class);
if (cm !=null) modelAdaptable = (IAdaptable)ob;
}
if (isUpdatableSelection(ob)) updateJob.schedule();
}
}
项目:eclipse-bash-editor
文件:BashSourceViewerConfiguration.java
/**
* Creates configuration by given adaptable
*
* @param adaptable
* must provide {@link ColorManager} and {@link IFile}
*/
public BashSourceViewerConfiguration(IAdaptable adaptable) {
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
this.fPreferenceStore = new ChainedPreferenceStore(
new IPreferenceStore[] { getPreferences().getPreferenceStore(), generalTextStore });
Assert.isNotNull(adaptable, "adaptable may not be null!");
this.annotationHoover = new BashEditorAnnotationHoover();
this.contentAssistant = new ContentAssistant();
contentAssistProcessor = new BashEditorSimpleWordContentAssistProcessor();
contentAssistant.enableColoredLabels(true);
contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
for (BashDocumentIdentifier identifier: BashDocumentIdentifiers.values()){
contentAssistant.setContentAssistProcessor(contentAssistProcessor, identifier.getId());
}
contentAssistant.addCompletionListener(contentAssistProcessor.getCompletionListener());
this.colorManager = adaptable.getAdapter(ColorManager.class);
Assert.isNotNull(colorManager, " adaptable must support color manager");
this.defaultTextAttribute = new TextAttribute(
colorManager.getColor(getPreferences().getColor(COLOR_NORMAL_TEXT)));
this.adaptable=adaptable;
}
项目:eclipse-bash-editor
文件:OpenWithBashEditor.java
protected IFile getSelectedFile() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
ISelection selection = window.getSelectionService().getSelection();
if (! (selection instanceof IStructuredSelection)){
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (!(firstElement instanceof IAdaptable)) {
return null;
}
IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class);
return file;
}
项目:Tarski
文件:CountMarkersInResourceHandler.java
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = MarkerFactory.getSelection();
if (selection instanceof ITreeSelection) {
ITreeSelection treeSelection = (ITreeSelection) selection;
if (treeSelection.getFirstElement() instanceof IOpenable
|| treeSelection.getFirstElement() instanceof IFile) {
IResource resource =
((IAdaptable) treeSelection.getFirstElement()).getAdapter(IResource.class);
List<IMarker> markers = MarkerFactory.findMarkers(resource);
MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Marker Count", null,
markers.size() + " marker(s)", MessageDialog.INFORMATION, new String[] {"OK"}, 0);
dialog.open();
}
}
return null;
}
项目:SurveyDSL
文件:GenerateATLHandler.java
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
TreeSelection selection = (TreeSelection) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable)
{
IFile file = (IFile)((IAdaptable)firstElement).getAdapter(IFile.class);
IPath path = file.getLocation();
try {
//TODO fix
SurveyGenerator.generateAll(path.toOSString(), path.toOSString());
MessageDialog.openInformation(shell, "Success", "Code was generated successfully");
} catch (Exception e) {
//MessageDialog.openError(shell, "Error", e.getMessage());
e.printStackTrace();
}
}
return null;
}
项目:apgas
文件:Handler.java
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IPath containerPath = new Path(Initializer.APGAS_CONTAINER_ID);
try {
final IJavaProject javaProject = JavaCore
.create(((IAdaptable) ((IStructuredSelection) HandlerUtil
.getCurrentSelection(event)).getFirstElement())
.getAdapter(IProject.class));
final IClasspathEntry[] entries = javaProject.getRawClasspath();
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER
&& entries[i].getPath().equals(containerPath)) {
return null;
}
}
final IClasspathEntry[] cp = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, cp, 0, entries.length);
cp[entries.length] = JavaCore.newContainerEntry(containerPath);
javaProject.setRawClasspath(cp, new NullProgressMonitor());
} catch (final Exception e) {
throw new ExecutionException(e.toString(), e);
}
return null;
}
项目:egradle
文件:EGradleLaunchShortCut.java
/**
* Resolves a type that can be launched from the given scope and launches in
* the specified mode.
*
* @param resources
* the java children to consider for a type that can be launched
* @param mode
* launch mode
* @param selectTitle
* prompting title for choosing a type to launch
* @param additionalScope
* additional scope for launch
* @param emptyMessage
* error message when no types are resolved for launching
*/
private void searchAndLaunch(Object[] resources, Object additionalScope, String mode, String selectTitle,
String emptyMessage) {
IResource resource = null;
Object object = resources[0];
if (object instanceof IResource) {
resource = (IResource) object;
} else if (object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) object;
resource = getLaunchableResource(adaptable);
} else {
throw new IllegalArgumentException("EGradle launch shortcut cannot handle object type:" + object);
}
if (resource != null) {
launch(resource, additionalScope, mode);
}
}
项目:egradle
文件:ShowDependenciesOfSelectecProjectHandler.java
private IProject findSelectedProject() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
if (selection ==null){
return null;
}
Object firstElement = selection.getFirstElement();
if (!(firstElement instanceof IAdaptable)) {
return null;
}
IProject project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject.class);
return project;
}
项目:egradle
文件:WorkingSetSupportTest.java
@Test
public void resolve__workingset_1_contains_project1__so_one_entry_for_workingset_is_returned() {
/* prepare */
ArrayList<IProject> projects = new ArrayList<>();
projects.add(mockedProject1);
projects.add(mockedProject2);
when(mockedManager.getAllWorkingSets()).thenReturn(new IWorkingSet[]{mockedWorkingSet1});
when(mockedWorkingSet1.getElements()).thenReturn(new IAdaptable[]{mockedProject1Adaptable});
/* execute */
List<WorkingSetData> workingSetDataList = supportToTest.resolveWorkingSetsForProjects(projects,
mockedManager);
/* test */
assertNotNull(workingSetDataList);
assertEquals(1,workingSetDataList.size());
WorkingSetData data = workingSetDataList.iterator().next();
assertEquals(mockedWorkingSet1, data.workingSet);
assertTrue(data.projectNamesContainedBefore.contains("project1"));
assertFalse(data.projectNamesContainedBefore.contains("project2"));
}
项目:egradle
文件:WorkingSetSupportTest.java
@Test
public void restore__workingset_1__will_have_project_1_and_2_after_restore() {
/* prepare */
ArrayList<IProject> projects = new ArrayList<>();
projects.add(mockedProject1);
projects.add(mockedProject2);
List<WorkingSetData> workingSetDataList = new ArrayList<>();
WorkingSetData data = new WorkingSetData();
data.projectNamesContainedBefore.add("project1");
data.projectNamesContainedBefore.add("project2");
data.workingSet=mockedWorkingSet1;
workingSetDataList.add(data);
/* execute */
supportToTest.restoreWorkingSetsForProjects(workingSetDataList,projects,mockedManager);
/* test */
verify(mockedWorkingSet1).setElements(eq(new IAdaptable[]{mockedProject1, mockedProject2}));
}
项目:egradle
文件:WorkingSetSupportTest.java
@Test
public void restore__workingset_1__will_have_project_1_and_2__and_contains_project_3_which_was_added_before__after_restore() {
/* prepare */
ArrayList<IProject> projects = new ArrayList<>();
projects.add(mockedProject1);
projects.add(mockedProject2);
when(mockedWorkingSet1.getElements()).thenReturn(new IAdaptable[]{mockedProject3Adaptable});
List<WorkingSetData> workingSetDataList = new ArrayList<>();
WorkingSetData data = new WorkingSetData();
data.projectNamesContainedBefore.add("project1");
data.projectNamesContainedBefore.add("project2");
data.workingSet=mockedWorkingSet1;
workingSetDataList.add(data);
/* execute */
supportToTest.restoreWorkingSetsForProjects(workingSetDataList,projects,mockedManager);
/* test */
verify(mockedWorkingSet1).setElements(eq(new IAdaptable[]{mockedProject3Adaptable, mockedProject1, mockedProject2}));
}
项目:egradle
文件:WorkingSetSupportTest.java
@Test
public void restore__workingset_1__will_have_project_1_and_2__and_contains_project_2_and_3_which_was_added_before__after_restore() {
/* prepare */
ArrayList<IProject> projects = new ArrayList<>();
projects.add(mockedProject1);
projects.add(mockedProject2);
when(mockedWorkingSet1.getElements()).thenReturn(new IAdaptable[]{mockedProject3Adaptable, mockedProject2Adaptable});
List<WorkingSetData> workingSetDataList = new ArrayList<>();
WorkingSetData data = new WorkingSetData();
data.projectNamesContainedBefore.add("project1");
data.projectNamesContainedBefore.add("project2");
data.workingSet=mockedWorkingSet1;
workingSetDataList.add(data);
/* execute */
supportToTest.restoreWorkingSetsForProjects(workingSetDataList,projects,mockedManager);
/* test */
verify(mockedWorkingSet1).setElements(eq(new IAdaptable[]{mockedProject3Adaptable, mockedProject2Adaptable, mockedProject1}));
}
项目:egradle
文件:GradleContentAssistProcessor.java
public GradleContentAssistProcessor(IAdaptable adaptable, RelevantCodeCutter codeCutter) {
if (adaptable == null) {
throw new IllegalArgumentException("adaptable may not be null!");
}
if (codeCutter == null) {
throw new IllegalArgumentException("codeCutter may not be null!");
}
this.adaptable = adaptable;
this.codeCutter = codeCutter;
this.proposalFactories = new ArrayList<>();
this.cachedProposals = new TreeSet<>();
this.completionListener = new CacheValidListener();
this.descriptionBuilder=new HTMLDescriptionBuilder();
addFactories();
}
项目:egradle
文件:GradleSourceViewerConfiguration.java
/**
* Creates configuration by given adaptable
*
* @param adaptable
* must provide {@link ColorManager} and {@link IFile}
*/
public GradleSourceViewerConfiguration(IAdaptable adaptable) {
super(adaptable, COLOR_NORMAL_TEXT);
Assert.isNotNull(adaptable, "adaptable may not be null!");
/* code completion */
this.contentAssistant = new ContentAssistant();
this.gradleContentAssistProcessor = new GradleContentAssistProcessor(adaptable, new RelevantCodeCutter());
contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_APPLY_KEYWORD.getId());
contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_KEYWORD.getId());
contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_TASK_KEYWORD.getId());
contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_VARIABLE.getId());
contentAssistant.addCompletionListener(gradleContentAssistProcessor.getCompletionListener());
// contentAssistant.enableColoredLabels(true); - when...
// ICompletionProposalExtension6 implemented
/* enable auto activation */
contentAssistant.enableAutoActivation(true);
/* set a propert orientation for proposal */
contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
}
项目:tlaplus
文件:UIHelper.java
/**
* Opens the new window containing the new perspective
*
* @param perspectiveId
* new perspective
* @param input
* IAdaptable, or null if no input
* @return IWorkbenchWindow instance
*
*/
public static IWorkbenchWindow openPerspectiveInNewWindow(String perspectiveId, IAdaptable input) {
IWorkbench workbench = Activator.getDefault().getWorkbench();
IWorkbenchWindow window = null;
try {
// avoids flicking, from implementation above
window = workbench.openWorkbenchWindow(perspectiveId, input);
// show intro
if (InitialPerspective.ID.equals(perspectiveId) && workbench.getIntroManager().hasIntro()) {
// IIntroPart intro =
workbench.getIntroManager().showIntro(window, true);
}
} catch (WorkbenchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return window;
}
项目:pde.source.lookup
文件:DownloadSourcesHandler.java
private Collection<IPackageFragmentRoot> getSelectedClasspathEntries(ISelection selection) {
if (!(selection instanceof ITreeSelection)) {
return Collections.emptyList();
}
ITreeSelection structuredSelection = (ITreeSelection) selection;
Set<IPackageFragmentRoot> fragments = new LinkedHashSet<>(structuredSelection.size());
for (Object o : structuredSelection.toList()) {
if (o instanceof IPackageFragmentRoot) {
IPackageFragmentRoot pfr = (IPackageFragmentRoot) o;
if (ClasspathUtils.isBinaryFragment(pfr) && belongsToPluginContainer(structuredSelection, pfr)) {
fragments.add(pfr);
}
} else if (isPluginContainer(o)) {
IAdaptable adaptable = (IAdaptable) o;
IWorkbenchAdapter wa = adaptable.getAdapter(IWorkbenchAdapter.class);
if (wa != null) {
Object[] children = wa.getChildren(o);
if (children instanceof IAdaptable[]) {
IAdaptable[] adaptables = (IAdaptable[]) children;
fragments.addAll(filterPackageFragmentRoots(adaptables));
}
}
}
}
return fragments;
}
项目:DarwinSPL
文件:HyexpressionNewProjectWizardLogic.java
/**
* <p>
* Adds the newly created project to the currently selected working set.
* </p>
*
* @param project the project to be added to the selected working set
*/
private void addProjectToSelectedWorkingSet(IProject project) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return;
}
ISelectionService selectionService = workbenchWindow.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) firstElement;
IWorkingSet workingSet = (IWorkingSet) adaptable.getAdapter(IWorkingSet.class);
if (workingSet != null) {
// new project wizard was invoked by right-clicking a working set
IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
workingSetManager.addToWorkingSets(project, new IWorkingSet[]{workingSet});
}
}
}
}
项目:DarwinSPL
文件:HyvalidityformulaNewProjectWizardLogic.java
/**
* <p>
* Adds the newly created project to the currently selected working set.
* </p>
*
* @param project the project to be added to the selected working set
*/
private void addProjectToSelectedWorkingSet(IProject project) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return;
}
ISelectionService selectionService = workbenchWindow.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) firstElement;
IWorkingSet workingSet = (IWorkingSet) adaptable.getAdapter(IWorkingSet.class);
if (workingSet != null) {
// new project wizard was invoked by right-clicking a working set
IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
workingSetManager.addToWorkingSets(project, new IWorkingSet[]{workingSet});
}
}
}
}
项目:DarwinSPL
文件:HydatavalueNewProjectWizardLogic.java
/**
* <p>
* Adds the newly created project to the currently selected working set.
* </p>
*
* @param project the project to be added to the selected working set
*/
private void addProjectToSelectedWorkingSet(IProject project) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return;
}
ISelectionService selectionService = workbenchWindow.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) firstElement;
IWorkingSet workingSet = (IWorkingSet) adaptable.getAdapter(IWorkingSet.class);
if (workingSet != null) {
// new project wizard was invoked by right-clicking a working set
IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
workingSetManager.addToWorkingSets(project, new IWorkingSet[]{workingSet});
}
}
}
}
项目:DarwinSPL
文件:HyconstraintsNewProjectWizardLogic.java
/**
* <p>
* Adds the newly created project to the currently selected working set.
* </p>
*
* @param project the project to be added to the selected working set
*/
private void addProjectToSelectedWorkingSet(IProject project) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return;
}
ISelectionService selectionService = workbenchWindow.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) firstElement;
IWorkingSet workingSet = (IWorkingSet) adaptable.getAdapter(IWorkingSet.class);
if (workingSet != null) {
// new project wizard was invoked by right-clicking a working set
IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
workingSetManager.addToWorkingSets(project, new IWorkingSet[]{workingSet});
}
}
}
}
项目:DarwinSPL
文件:HymanifestNewProjectWizardLogic.java
/**
* <p>
* Adds the newly created project to the currently selected working set.
* </p>
*
* @param project the project to be added to the selected working set
*/
private void addProjectToSelectedWorkingSet(IProject project) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return;
}
ISelectionService selectionService = workbenchWindow.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) firstElement;
IWorkingSet workingSet = (IWorkingSet) adaptable.getAdapter(IWorkingSet.class);
if (workingSet != null) {
// new project wizard was invoked by right-clicking a working set
IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
workingSetManager.addToWorkingSets(project, new IWorkingSet[]{workingSet});
}
}
}
}
项目:Sparrow
文件:AddRemoveOutcodeNatureHandler.java
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
.hasNext();) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element)
.getAdapter(IProject.class);
}
if (project != null) {
try {
toggleNature(project);
} catch (CoreException e) {
throw new ExecutionException("Failed to toggle nature", e);
}
}
}
}
return null;
}
项目:subclipse
文件:SvnPropertiesView.java
/**
* called when the selection changed on another part
*/
private void handlePartSelectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(selection instanceof IStructuredSelection))
return;
try {
Object first = ((IStructuredSelection)selection).getFirstElement();
if (first instanceof IAdaptable) {
IAdaptable a = (IAdaptable) first;
Object adapter = a.getAdapter(IResource.class);
if (adapter instanceof IResource) {
IResource resource = (IResource)adapter;
// If the resource isn't open or doesn't exist it won't have properties
if (!resource.isAccessible()) {
showSvnProperties(null);
} else {
ISVNLocalResource svnResource = (ISVNLocalResource)resource.getAdapter(ISVNLocalResource.class);
showSvnProperties(svnResource);
}
}
}
} catch (SVNException e) {
}
}
项目:google-cloud-eclipse
文件:AdapterUtil.java
public static <T> T adapt(Object o, Class<T> cls) {
if (cls.isInstance(o)) {
return cls.cast(o);
}
if (o instanceof IAdaptable) {
Object instance = ((IAdaptable) o).getAdapter(cls);
if (instance != null) {
return cls.cast(instance);
}
}
Object adapted = Platform.getAdapterManager().loadAdapter(o, cls.getName());
if (adapted != null) {
return cls.cast(adapted);
}
return null;
}
项目:hybris-commerce-eclipse-plugin
文件:AddRemoveHybrisNatureHandler.java
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
ISelection selection = HandlerUtil.getCurrentSelection(event);
//
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
.hasNext();) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element)
.getAdapter(IProject.class);
}
if (project != null) {
toggleNature(project);
}
}
}
return null;
}
项目:n4js
文件:N4JSProjectExplorerProblemsDecorator.java
/**
* Increased visibility for testing purposes.
*
* <p>
* {@inheritDoc}
*/
@Override
@VisibleForTesting
public int computeAdornmentFlags(final Object obj) {
if (!(obj instanceof WorkingSet)) {
return super.computeAdornmentFlags(obj);
}
final WorkingSet workingSet = (WorkingSet) obj;
final IAdaptable[] elements = workingSet.getElements();
int result = 0;
for (int i = 0; i < elements.length; i++) {
final IAdaptable element = elements[i];
final int flags = super.computeAdornmentFlags(element);
if ((flags & BUILDPATH_ERROR) != 0) {
return BUILDPATH_ERROR;
}
result |= flags;
}
if ((result & ERROR) != 0) {
return ERROR;
} else if ((result & WARNING) != 0) {
return WARNING;
} else {
return NO_ADORNMENT;
}
}
项目:n4js
文件:N4JSProjectInWorkingSetDropAdapterAssistant.java
private boolean workingSetContains(WorkingSet workingSet, IProject project) {
for (IAdaptable element : workingSet.getElements()) {
if (project.equals(element.getAdapter(IProject.class))) {
return true;
}
}
return false;
}
项目:n4js
文件:N4JSProjectActionGroup.java
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;
}
项目:eclipse-jenkins-editor
文件:JenkinsEditorOutlineContentProvider.java
public JenkinsEditorOutlineContentProvider(IAdaptable adaptable) {
outlineErrorMarkerHelper= createOutlineErrorMarkerHelper();
if (adaptable==null){
return;
}
this.editor = adaptable.getAdapter(IExtendedEditor.class);
this.logSupport = editor.getLogSupport();
}
项目:gemoc-studio-modeldebugging
文件:GemocSequentialPropertyTester.java
protected boolean isExecutableDomainSpecificModel(IAdaptable receiver){
IFile modelFile = (IFile)(receiver).getAdapter(IFile.class);
if(modelFile !=null){
return existsDSMLWithFileExtension(modelFile.getFileExtension());
}
return false;
}
项目:neoscada
文件:AdapterHelper.java
/**
* 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 );
}
}
项目:neoscada
文件:AdapterHelper.java
/**
* 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>
*
* @since 1.2
* @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 );
}
}
项目:neoscada
文件:ConnectionDiscovererAdapterFactory.java
@Override
public <T> T getAdapter ( final Object adaptableObject, final Class<T> adapterType )
{
if ( adaptableObject instanceof IAdaptable )
{
return ( (IAdaptable)adaptableObject ).getAdapter ( adapterType );
}
return null;
}