예제 #1
0
  private static File[] convertSelectionToFiles(ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) return new File[0];

    IStructuredSelection structSel = (IStructuredSelection) selection;
    List<File> files = new ArrayList<File>(structSel.size());

    for (Iterator<?> iter = structSel.iterator(); iter.hasNext(); ) {
      Object element = iter.next();
      if (element instanceof IFile) files.add(((IFile) element).getLocation().toFile());
      else if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        IFile ifile = (IFile) adaptable.getAdapter(IFile.class);
        if (ifile != null) {
          files.add(ifile.getLocation().toFile());
        } else {
          File file = (File) adaptable.getAdapter(File.class);
          if (file != null) {
            files.add(file);
          }
        }
      }
    }

    return files.toArray(new File[files.size()]);
  }
  @Override
  public void createPartControl(Composite parent) {

    // create viewer
    graphViewer = new VisualisationGraphViewer(parent, SWT.NONE);
    graphViewer.setLayoutAlgorithm(layout.getDefault());
    graphViewer.setLabelProvider(labelprovider);
    graphViewer.setContentProvider(contentprovider);
    if (VisualisationSettings.filterPrimitiveTypes) {
      graphViewer.addFilter(VisualisationSettings.primitiveTypeFilter);
    }
    if (VisualisationSettings.filterUndefinedValues) {
      graphViewer.addFilter(VisualisationSettings.undefinedValuesFilter);
    }
    graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
    // TODO why is this needed for selection synchronizing?
    graphViewer.setUseHashlookup(false);

    initializeActions();
    createToolbar();
    createMenu();

    // double click on nodes
    graphViewer
        .getGraphControl()
        .addMouseListener(
            new MouseAdapter() {

              @Override
              public void mouseDoubleClick(MouseEvent e) {
                toggleOpen.run();
              }
            });

    // graphViewer.getGraphControl().addKeyListener(new KeyAdapter() {
    //
    // @Override
    // public void keyReleased(KeyEvent e) {
    // if (e.keyCode == SWT.DEL || e.character == 8) {
    // hideNode.run();
    // }
    //
    // }
    //
    // });

    // listener for debug context
    listener = new DebugContextListener(this);
    DebugUITools.getDebugContextManager().addDebugContextListener(listener);

    // Check if there is an already started debug context
    IAdaptable dc = DebugUITools.getDebugContext();
    if (dc != null) {
      Object o = dc.getAdapter(IStackFrame.class);
      if (o instanceof IStackFrame) setStackFrame((IStackFrame) o);
    }

    getSite().setSelectionProvider(graphViewer);
    selectionSynchronizer = new VariableSelectionSynchronizer(getSite());
  }
예제 #3
0
 /**
  * Method filterResources filters the given resources using the given working set.
  *
  * @param current
  * @param resources
  * @return ICVSRemoteResource[]
  */
 public ICVSRemoteResource[] filterResources(
     IWorkingSet workingSet, ICVSRemoteResource[] resources) {
   if (workingSet == null) return resources;
   // get the projects associated with the working set
   IAdaptable[] adaptables = workingSet.getElements();
   Set projects = new HashSet();
   for (int i = 0; i < adaptables.length; i++) {
     IAdaptable adaptable = adaptables[i];
     Object adapted = adaptable.getAdapter(IResource.class);
     if (adapted != null) {
       // Can this code be generalized?
       IProject project = ((IResource) adapted).getProject();
       projects.add(project);
     }
   }
   List result = new ArrayList();
   for (int i = 0; i < resources.length; i++) {
     ICVSRemoteResource resource = resources[i];
     for (Iterator iter = projects.iterator(); iter.hasNext(); ) {
       IProject project = (IProject) iter.next();
       if (project.getName().equals(resource.getName())) {
         result.add(resource);
         break;
       }
     }
   }
   return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
 }
  @Override
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    name = createTextWithLabel(composite, "Name");
    wkn = createTextWithLabel(composite, "WKN");
    isin = createTextWithLabel(composite, "Isin");
    ticker = createTextWithLabel(composite, "Ticker");
    morningstarSymbol = createTextWithLabel(composite, "Morningstar");
    fourTradersUrl = createTextWithLabel(composite, "4-Traders Url");

    Label label = new Label(composite, SWT.NONE);
    label.setText("Override existing price data");
    overridePriceDate = new Button(composite, SWT.CHECK);

    IAdaptable adapter = getElement();
    Security security = (Security) adapter.getAdapter(Security.class);
    name.setText(security.getName());
    wkn.setText(StringUtils.defaultString(security.getWKN()));
    isin.setText(StringUtils.defaultString(security.getISIN()));
    ticker.setText(StringUtils.defaultString(security.getTicker()));
    morningstarSymbol.setText(StringUtils.defaultString(security.getMorningstarSymbol()));
    fourTradersUrl.setText(
        StringUtils.defaultString(security.getConfigurationValue("fourTrasdersUrl")));
    overridePriceDate.setSelection(
        Boolean.valueOf(security.getConfigurationValue(OVERRIDE_EXISTING_PRICE_DATA))
            .booleanValue());

    return composite;
  }
예제 #5
0
 private void addOpenWithMenu(IMenuManager menu) {
   ISelection selection = getContext().getSelection();
   if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) return;
   IStructuredSelection ss = (IStructuredSelection) selection;
   if (ss.size() != 1) return;
   Object o = ss.getFirstElement();
   if (!(o instanceof IAdaptable)) return;
   IAdaptable element = (IAdaptable) o;
   Object resource = element.getAdapter(IResource.class);
   if (element instanceof IStorage && !(resource instanceof IFile)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(new OpenStorageWithMenu(fSite.getPage(), element));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   } else if ((element instanceof IModelElement)
       || (element.getAdapter(IModelElement.class) != null)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(
         new OpenModelElementWithMenu(
             fSite.getPage(), (IModelElement) element.getAdapter(IModelElement.class)));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   } else if ((resource instanceof IFile)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(new OpenWithMenu(fSite.getPage(), (IFile) resource));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   }
 }
 /**
  * Returns the launch to which the current selection belongs.
  *
  * @return the launch to which the current selection belongs.
  */
 protected ILaunch getCurrentLaunch() {
   IAdaptable context = DebugUITools.getDebugContext();
   if (context != null) {
     return context.getAdapter(ILaunch.class);
   }
   return null;
 }
예제 #7
0
 private ScriptStackFrame getFrame() {
   IAdaptable adaptable = DebugUITools.getDebugContext();
   if (adaptable != null) {
     return (ScriptStackFrame) adaptable.getAdapter(ScriptStackFrame.class);
   }
   return null;
 }
예제 #8
0
  public void selectionChanged(IAction action, ISelection selection) {
    ArrayList<IFolder> sFolders = new ArrayList<IFolder>();
    IFolder folder = null;
    if (selection != null && selection instanceof IStructuredSelection) {
      IStructuredSelection ss = (IStructuredSelection) selection;

      for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
        Object obj = iter.next();
        if (obj instanceof IFolder) {
          folder = (IFolder) obj;
        } else if (obj instanceof IAdaptable) {
          IAdaptable a = (IAdaptable) obj;
          IResource res = (IResource) a.getAdapter(IResource.class);
          if (res instanceof IFolder) {
            folder = (IFolder) res;
          }
        }

        if (folder != null && folder.isSynchronized(IResource.DEPTH_ZERO)) {
          sFolders.add(folder);
        } else if (!folder.isSynchronized(IResource.DEPTH_ZERO)) {
          MessageDialog.openInformation(
              shell,
              "Synchronization error",
              "The selected folder is not synchronized with the system file, please refresh the project!");
        }
      }
    }

    if (sFolders.isEmpty()) {
      selectedFolders = null;
    } else {
      selectedFolders = sFolders.toArray(new IFolder[sFolders.size()]);
    }
  }
  /**
   * Copied from Util.getAdapter (from eclipse 3.3: not available in eclipse 3.2)
   *
   * <p>If it is possible to adapt the given object to the given type, this returns the adapter.
   * Performs the following checks:
   *
   * <ol>
   *   <li>Returns <code>sourceObject</code> if it is an instance of the adapter type.
   *   <li>If sourceObject implements IAdaptable, it is queried for adapters.
   *   <li>If sourceObject is not an instance of PlatformObject (which would have already done so),
   *       the adapter manager is queried for adapters
   * </ol>
   *
   * Otherwise returns null.
   *
   * @param sourceObject object to adapt, or null
   * @param adapterType type to adapt to
   * @return a representation of sourceObject that is assignable to the adapter type, or null if no
   *     such representation exists
   */
  public static Object utilGetAdapter(Object sourceObject, Class adapterType) {
    Assert.isNotNull(adapterType);
    if (sourceObject == null) {
      return null;
    }
    if (adapterType.isInstance(sourceObject)) {
      return sourceObject;
    }

    if (sourceObject instanceof IAdaptable) {
      IAdaptable adaptable = (IAdaptable) sourceObject;

      Object result = adaptable.getAdapter(adapterType);
      if (result != null) {
        // Sanity-check
        Assert.isTrue(adapterType.isInstance(result));
        return result;
      }
    }

    if (!(sourceObject instanceof PlatformObject)) {
      Object result = Platform.getAdapterManager().getAdapter(sourceObject, adapterType);
      if (result != null) {
        return result;
      }
    }

    return null;
  }
  public void launch(ISelection selection, String mode) {
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      Object object = structuredSelection.getFirstElement();

      IContainer basedir = null;
      if (object instanceof IProject || object instanceof IFolder) {
        basedir = (IContainer) object;
      } else if (object instanceof IFile) {
        basedir = ((IFile) object).getParent();
      } else if (object instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) object;
        Object adapter = adaptable.getAdapter(IProject.class);
        if (adapter != null) {
          basedir = (IContainer) adapter;
        } else {
          adapter = adaptable.getAdapter(IFolder.class);
          if (adapter != null) {
            basedir = (IContainer) adapter;
          } else {
            adapter = adaptable.getAdapter(IFile.class);
            if (adapter != null) {
              basedir = ((IFile) object).getParent();
            }
          }
        }
      }

      launch(basedir, mode);
    }
  }
  @Override
  public StyledString getStyledText(Object element) {
    if (element instanceof TreeNode) {
      element = ((TreeNode<?>) element).data;
    }

    if (element instanceof ICustomLineElement) {
      return getLineElementLabel((ICustomLineElement) element);
    }

    if (!(element instanceof IResource)) {
      IResource resource = null;
      if (element instanceof IAdaptable) {
        IAdaptable iAdaptable = (IAdaptable) element;
        resource = iAdaptable.getAdapter(IResource.class);
        if (resource != null) {
          if (element instanceof ICustomModule) {
            return getColoredLabelWithCounts(resource, new StyledString(element.toString()));
          }
          element = resource;
        }
      }
      if (!(element instanceof IResource)) {
        return new StyledString(element.toString());
      }
    }

    IResource resource = (IResource) element;
    if (!resource.exists()) {
      new StyledString("<removed resource>");
    }

    String name = BasicElementLabels.getResourceName(resource);
    return getColoredLabelWithCounts(resource, new StyledString(name));
  }
    /** @generated */
    protected List getObjectsBeingDropped() {
      TransferData data = getCurrentEvent().currentDataType;
      Collection uris = new HashSet();

      List result = new ArrayList();
      Object transferedObject = getJavaObject(data);
      if (transferedObject instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) transferedObject;
        for (Iterator it = selection.iterator(); it.hasNext(); ) {
          Object nextSelectedObject = it.next();
          if (nextSelectedObject instanceof SqlmodelNavigatorItem) {
            View view = ((SqlmodelNavigatorItem) nextSelectedObject).getView();
            nextSelectedObject = view.getElement();
          } else if (nextSelectedObject instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) nextSelectedObject;
            nextSelectedObject = adaptable.getAdapter(EObject.class);
          }

          if (nextSelectedObject instanceof EObject) {
            EObject modelElement = (EObject) nextSelectedObject;
            Resource modelElementResource = modelElement.eResource();
            uris.add(
                modelElementResource
                    .getURI()
                    .appendFragment(modelElementResource.getURIFragment(modelElement)));
          }

          if (nextSelectedObject instanceof EObject) {
            result.add(nextSelectedObject);
          }
        }
      }
      return result;
    }
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = (IResource) adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = (IJavaElement) resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }

    return jelem;
  }
 protected IFrameDMContext getFrame() {
   IAdaptable adaptable = getSelectionAdaptable();
   if (adaptable != null) {
     return (IFrameDMContext) adaptable.getAdapter(IFrameDMContext.class);
   }
   return null;
 }
예제 #15
0
 /**
  * Returns the currently active stack frame, or <code>null</code> if none.
  *
  * @return the currently active stack frame, or <code>null</code>
  */
 protected IJavaStackFrame getStackFrame() {
   IAdaptable debugContext = DebugUITools.getDebugContext();
   IJavaStackFrame frame = null;
   if (debugContext != null) {
     frame = (IJavaStackFrame) debugContext.getAdapter(IJavaStackFrame.class);
   }
   return frame;
 }
예제 #16
0
 /**
  * Returns the edited {@link IProject}.
  *
  * @return
  */
 private IProject getProject() {
   IAdaptable adaptable = getElement();
   if (adaptable != null) {
     IProject elem = (IProject) adaptable.getAdapter(IProject.class);
     if (elem != null) return elem;
   }
   return null;
 }
 /** @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((ReplaySinkEditPart) sourceEditPart, targetEditPart);
 }
 /** @generated */
 public IParser getParser(IAdaptable hint) {
   String viewType = (String) hint.getAdapter(String.class);
   IElementType type = (IElementType) hint.getAdapter(IElementType.class);
   if (type == null) {
     EObject element = (EObject) hint.getAdapter(EObject.class);
     type = ElementTypeRegistry.getInstance().getElementType(element);
   }
   return getParser(type, viewType);
 }
 /** @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(
       (HTTPEndPointOutputConnector2EditPart) sourceEditPart, targetEditPart);
 }
  /**
   * Utility method to inspect a selection to find a Java element.
   *
   * @param selection the selection to be inspected
   * @return a Java element to be used as the initial selection, or <code>null</code>, if no Java
   *     element exists in the given selection
   */
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }
    if (jelem == null) {
      IWorkbenchPart part = JavaPlugin.getActivePage().getActivePart();
      if (part instanceof ContentOutline) {
        part = JavaPlugin.getActivePage().getActiveEditor();
      }

      if (part instanceof IViewPartInputProvider) {
        Object elem = ((IViewPartInputProvider) part).getViewPartInput();
        if (elem instanceof IJavaElement) {
          jelem = (IJavaElement) elem;
        }
      }
    }

    if (jelem == null || jelem.getElementType() == IJavaElement.JAVA_MODEL) {
      try {
        IJavaProject[] projects = JavaCore.create(getWorkspaceRoot()).getJavaProjects();
        if (projects.length == 1) {
          IClasspathEntry[] rawClasspath = projects[0].getRawClasspath();
          for (int i = 0; i < rawClasspath.length; i++) {
            if (rawClasspath[i].getEntryKind()
                == IClasspathEntry.CPE_SOURCE) { // add only if the project contains a source folder
              jelem = projects[0];
              break;
            }
          }
        }
      } catch (JavaModelException e) {
        JavaPlugin.log(e);
      }
    }
    return jelem;
  }
 public IResource extractSelection(ISelection sel) {
   if (!(sel instanceof IStructuredSelection)) return null;
   IStructuredSelection ss = (IStructuredSelection) sel;
   Object element = ss.getFirstElement();
   if (element instanceof IResource) return (IResource) element;
   if (!(element instanceof IAdaptable)) return null;
   IAdaptable adaptable = (IAdaptable) element;
   Object adapter = adaptable.getAdapter(IResource.class);
   return (IResource) adapter;
 }
예제 #22
0
 /** Performs conversion of incoming element to internal representation. */
 protected boolean checkElement() {
   IAdaptable el = super.getElement();
   if (el instanceof ICElement) internalElement = ((ICElement) el).getResource();
   else if (el instanceof IResource) internalElement = (IResource) el;
   else internalElement = (IResource) el.getAdapter(IResource.class);
   if (internalElement == null) return false;
   isProject = internalElement instanceof IProject;
   isFolder = internalElement instanceof IFolder;
   isFile = internalElement instanceof IFile;
   return true;
 }
 /** @generated */
 public IParser getParser(IAdaptable hint) {
   String vid = (String) hint.getAdapter(String.class);
   if (vid != null) {
     return getParser(AtomicVisualIDRegistry.getVisualID(vid));
   }
   View view = (View) hint.getAdapter(View.class);
   if (view != null) {
     return getParser(AtomicVisualIDRegistry.getVisualID(view));
   }
   return null;
 }
 /** @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(
       (edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.FinalStateEditPart)
           sourceEditPart,
       targetEditPart);
 }
  /* (non-Javadoc)
   * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
   * tau 21.03.2005
   */
  protected void doSaveDocument(
      IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException {

    if (element instanceof IFileEditorInput) {
      doSaveFileResource(monitor, element, document, overwrite);
    } else if (element instanceof IAdaptable) {
      // reuses code from TextFileDocumentProvider to handle external files (195615)
      // TODO consider converting the super class to TextFileDocumentProvider
      IAdaptable adaptable = (IAdaptable) element;

      ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
      ITextFileBuffer fileBuffer = null;
      LocationKind locationKind = null;

      ILocationProvider provider =
          (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
      if (provider instanceof ILocationProviderExtension) {
        URI uri = ((ILocationProviderExtension) provider).getURI(element);
        if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
          IFileStore fileStore = EFS.getStore(uri);
          manager.connectFileStore(fileStore, getProgressMonitor());
          fileBuffer = manager.getFileStoreTextFileBuffer(fileStore);
        }
      }
      if (fileBuffer == null && provider != null) {
        IPath location = provider.getPath(element);
        if (location != null) {
          locationKind = LocationKind.NORMALIZE;
          manager.connect(location, locationKind, getProgressMonitor());
          fileBuffer = manager.getTextFileBuffer(location, locationKind);
        }
      }

      if (fileBuffer != null) {
        fileBuffer.getDocument().set(document.get());
        fileBuffer.commit(null, true);
      }
    }

    // tau 21.03.05
    // First attempt show Message Connection through SQLScrapbookEditorInput
    if (element instanceof SQLScrapbookEditorInput)
      ((SQLScrapbookEditorInput) element).showMessageConnection();
    // Second attempt show Message Connection through sqlEditor
    IEditorPart editor =
        PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow()
            .getActivePage()
            .findEditor((IEditorInput) element);
    if ((editor != null) && (editor instanceof SQLEditor)) {
      ((SQLEditor) editor).refreshConnectionStatus();
    }
  }
예제 #26
0
 @Override
 public boolean performOk() {
   IAdaptable adapter = getElement();
   Security security = (Security) adapter.getAdapter(Security.class);
   security.setName(name.getText());
   security.setWKN(wkn.getText());
   security.setISIN(isin.getText());
   security.setTicker(ticker.getText());
   security.setMorningstarSymbol(morningstarSymbol.getText());
   security.putConfigurationValue("fourTrasdersUrl", fourTradersUrl.getText());
   return super.performOk();
 }
 /**
  * Get the resource this properties page is for
  *
  * @return IResource for this properties page or null if there is no IResource
  */
 private IResource getResource() {
   IResource resource = null;
   IAdaptable adaptable = getElement();
   if (adaptable instanceof IResource) {
     resource = (IResource) adaptable;
   } else if (adaptable != null) {
     Object o = adaptable.getAdapter(IResource.class);
     if (o instanceof IResource) {
       resource = (IResource) o;
     }
   }
   return resource;
 }
 public static String evaluateEnclosingProject(IAdaptable adaptable) {
   IProject project = (IProject) adaptable.getAdapter(IProject.class);
   if (project == null) {
     IResource resource = (IResource) adaptable.getAdapter(IResource.class);
     if (resource != null) {
       project = resource.getProject();
     }
   }
   if (project != null && project.isAccessible()) {
     return project.getName();
   }
   return null;
 }
예제 #29
0
 private void setActiveSession() {
   // if a simulation session is running, we should initialize with its
   // content
   IAdaptable debugContext = DebugUITools.getDebugContext();
   if (debugContext != null) {
     Object debugTarget = debugContext.getAdapter(IDebugTarget.class);
     if (debugTarget != null && debugTarget instanceof SCTDebugTarget) {
       if (!((SCTDebugTarget) debugTarget).isTerminated()) {
         this.debugTarget = (SCTDebugTarget) debugTarget;
         setInput(this.debugTarget);
       }
     }
   }
 }
 @Override
 public IProject from(final ISelection selection) {
   if (selection != null && selection instanceof IStructuredSelection) {
     final Object element = ((IStructuredSelection) selection).getFirstElement();
     if (element instanceof IResource) {
       return ((IResource) element).getProject();
     } else if (element instanceof IAdaptable) {
       final IAdaptable adaptable = (IAdaptable) element;
       final IResource resource = (IResource) adaptable.getAdapter(IResource.class);
       return resource.getProject();
     }
   }
   return null;
 }