コード例 #1
0
  public void testOpenUrl() {
    if (!PlatformUiUtil.hasInternalBrowser()) {
      return;
    }

    TasksUiUtil.openUrl(null);
    assertEquals(1, activePage.getEditorReferences().length);
    IEditorPart editor = activePage.getEditorReferences()[0].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor.getClass());
    assertEquals(WebBrowserEditorInput.class, editor.getEditorInput().getClass());
    assertEquals(null, ((WebBrowserEditorInput) editor.getEditorInput()).getURL());

    TasksUiUtil.openUrl("http://eclipse.org/mylyn");
    assertEquals(2, activePage.getEditorReferences().length);
    editor = activePage.getEditorReferences()[0].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor.getClass());
    assertEquals(WebBrowserEditorInput.class, editor.getEditorInput().getClass());
    assertEquals(null, ((WebBrowserEditorInput) editor.getEditorInput()).getURL());

    IEditorPart editor2 = activePage.getEditorReferences()[1].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor2.getClass());
    assertEquals(WebBrowserEditorInput.class, editor2.getEditorInput().getClass());
    assertNotNull(((WebBrowserEditorInput) editor2.getEditorInput()).getURL());
    assertEquals(
        "http://eclipse.org/mylyn",
        ((WebBrowserEditorInput) editor2.getEditorInput()).getURL().toString());
  }
コード例 #2
0
 public void testOpenTaskFromString() {
   if (!PlatformUiUtil.hasInternalBrowser()) {
     return;
   }
   TasksUiUtil.openTask((String) null);
   assertEquals(1, activePage.getEditorReferences().length);
   IEditorPart editor = activePage.getEditorReferences()[0].getEditor(true);
   assertEquals(WebBrowserEditor.class, editor.getClass());
 }
コード例 #3
0
  /**
   * Find Open Editor for the currently selected ModelExtensionDefinition
   *
   * @param selectedMedFile the mxd file to check
   * @return the currently open editor or <code>null</code> if none open
   */
  private static IEditorPart getOpenEditor(IFile selectedMedFile) {
    final IWorkbenchWindow window = Activator.getDefault().getCurrentWorkbenchWindow();

    if (window != null) {
      final IWorkbenchPage page = window.getActivePage();

      if (page != null) {
        // look through the open editors and see if there is one available for this model file.
        IEditorReference[] editors = page.getEditorReferences();

        for (int i = 0; i < editors.length; ++i) {
          IEditorPart editor = editors[i].getEditor(false);

          if (editor != null) {
            IEditorInput input = editor.getEditorInput();

            if (input instanceof IFileEditorInput) {
              if ((selectedMedFile != null)
                  && selectedMedFile.equals(((IFileEditorInput) input).getFile())) {
                return editor;
              }
            }
          }
        }
      }
    }

    return null;
  }
コード例 #4
0
  /**
   * Returns a VDB editor given a vdb resource if editor is open
   *
   * @param vdb the vdb
   * @return the vdb editor
   */
  public static VdbEditor getVdbEditorForFile(IResource vdb) {
    if (vdb != null && vdb.exists()) {
      IWorkbenchWindow window = UiPlugin.getDefault().getCurrentWorkbenchWindow();

      if (window != null) {
        final IWorkbenchPage page = window.getActivePage();

        if (page != null) {
          // look through the open editors and see if there is one available for this model file.
          IEditorReference[] editors = page.getEditorReferences();
          for (int i = 0; i < editors.length; ++i) {

            IEditorPart editor = editors[i].getEditor(false);
            if (editor != null) {
              IEditorInput input = editor.getEditorInput();
              if (input instanceof IFileEditorInput) {
                if (vdb.equals(((IFileEditorInput) input).getFile())
                    || vdb.getFullPath()
                        .equals(((IFileEditorInput) input).getFile().getFullPath())) {
                  // found it;
                  if (ModelUtil.isVdbArchiveFile(vdb)) {
                    return (VdbEditor) editor;
                  }
                  break;
                }
              }
            }
          }
        }
      }
    }

    return null;
  }
コード例 #5
0
  @Override
  public void setUp() throws Exception {
    taskList = TasksUiPlugin.getTaskList();

    TaskTestUtil.resetTaskListAndRepositories();
    TasksUiPlugin.getDefault().getLocalTaskRepository();

    cat1 = new TaskCategory("First Category");
    taskList.addCategory(cat1);

    cat1task1 = TasksUiInternal.createNewLocalTask("task 1");
    cat1task1.setPriority(PriorityLevel.P1.toString());
    cat1task1.setCompletionDate(new Date());
    taskList.addTask(cat1task1, cat1);

    cat1task2 = TasksUiInternal.createNewLocalTask("task 2");
    cat1task2.setPriority(PriorityLevel.P2.toString());
    taskList.addTask(cat1task2, cat1);

    assertEquals(cat1.getChildren().size(), 2);

    activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    assertTrue(activePage.closeAllEditors(false));
    assertEquals(0, activePage.getEditorReferences().length);
  }
コード例 #6
0
 private void setSelectedEditor(String fileName) {
   outer:
   for (IWorkbenchWindow w : PlatformUI.getWorkbench().getWorkbenchWindows()) {
     for (IWorkbenchPage p : w.getPages()) {
       for (IEditorReference e : p.getEditorReferences()) {
         try {
           if (e.getEditorInput() instanceof IFileEditorInput) {
             IFileEditorInput editorInput = (IFileEditorInput) e.getEditorInput();
             if (editorInput.getFile().getParent().findMember("opaeum.properties") != null) {
               for (IResource r : editorInput.getFile().getParent().members()) {
                 if (r.getName().equals(fileName)) {
                   selectedEditor = e.getEditor(true);
                   break outer;
                 }
               }
             }
           }
         } catch (PartInitException e1) {
           e1.printStackTrace();
         } catch (CoreException e2) {
           e2.printStackTrace();
         }
       }
     }
   }
 }
 private boolean hasOpenEditors() {
   for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
     for (IWorkbenchPage page : window.getPages()) {
       if (page.getEditorReferences().length > 0) return true;
     }
   }
   return false;
 }
  /**
   * DOC smallet Comment method "openRoutineEditor".
   *
   * @param item
   * @throws SystemException
   * @throws PartInitException
   */
  public IEditorPart openSQLPatternEditor(SQLPatternItem item, boolean readOnly)
      throws SystemException, PartInitException {
    if (item == null) {
      return null;
    }
    ICodeGeneratorService service =
        (ICodeGeneratorService)
            GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);

    ECodeLanguage lang =
        ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY))
            .getProject()
            .getLanguage();
    ISQLPatternSynchronizer routineSynchronizer = service.getSQLPatternSynchronizer();

    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();

    IEditorReference[] editorParts = page.getEditorReferences();
    String talendEditorID =
        "org.talend.designer.core.ui.editor.StandAloneTalend"
            + lang.getCaseName()
            + "Editor"; //$NON-NLS-1$ //$NON-NLS-2$
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
      IEditorPart editor = reference.getEditor(false);
      if (talendEditorID.equals(editor.getSite().getId())) {
        // TextEditor talendEditor = (TextEditor) editor;
        RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
        Item item2 = editorInput.getItem();
        if (item2 != null
            && item2 instanceof SQLPatternItem
            && item2.getProperty().getId().equals(item.getProperty().getId())) {
          if (item2.getProperty().getVersion().equals(item.getProperty().getVersion())) {
            page.bringToTop(editor);
            found = true;
            talendEditor = editor;
            break;
          } else {
            page.closeEditor(editor, false);
          }
        }
      }
    }

    if (!found) {
      routineSynchronizer.syncSQLPattern(item, true);
      IFile file = routineSynchronizer.getSQLPatternFile(item);

      RepositoryEditorInput input = new RepositoryEditorInput(file, item);
      input.setReadOnly(readOnly);
      talendEditor = page.openEditor(input, talendEditorID); // $NON-NLS-1$
    }

    return talendEditor;
  }
コード例 #9
0
  public void testFlagNoRichEditor() throws Exception {
    if (!PlatformUiUtil.hasInternalBrowser()) {
      return;
    }

    TasksUiUtil.openUrl(null);
    assertEquals(1, activePage.getEditorReferences().length);
    IEditorPart editor = activePage.getEditorReferences()[0].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor.getClass());
    assertEquals(WebBrowserEditorInput.class, editor.getEditorInput().getClass());
    assertEquals(null, ((WebBrowserEditorInput) editor.getEditorInput()).getURL());
    WebBrowserEditorInput input = ((WebBrowserEditorInput) editor.getEditorInput());
    Field f = input.getClass().getDeclaredField("style");
    f.setAccessible(true);
    int style = (Integer) f.get(input);
    assertFalse((style & BrowserUtil.NO_RICH_EDITOR) == 0);

    TasksUiUtil.openUrl("http://eclipse.org/mylyn");
    assertEquals(2, activePage.getEditorReferences().length);
    editor = activePage.getEditorReferences()[0].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor.getClass());
    assertEquals(WebBrowserEditorInput.class, editor.getEditorInput().getClass());
    assertEquals(null, ((WebBrowserEditorInput) editor.getEditorInput()).getURL());
    input = ((WebBrowserEditorInput) editor.getEditorInput());
    f = input.getClass().getDeclaredField("style");
    f.setAccessible(true);
    style = (Integer) f.get(input);
    assertFalse((style & BrowserUtil.NO_RICH_EDITOR) == 0);

    IEditorPart editor2 = activePage.getEditorReferences()[1].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor2.getClass());
    assertEquals(WebBrowserEditorInput.class, editor2.getEditorInput().getClass());
    assertNotNull(((WebBrowserEditorInput) editor2.getEditorInput()).getURL());
    assertEquals(
        "http://eclipse.org/mylyn",
        ((WebBrowserEditorInput) editor2.getEditorInput()).getURL().toString());
    input = ((WebBrowserEditorInput) editor.getEditorInput());
    f = input.getClass().getDeclaredField("style");
    f.setAccessible(true);
    style = (Integer) f.get(input);
    assertFalse((style & BrowserUtil.NO_RICH_EDITOR) == 0);

    // open task should not set FLAG_NO_RICH_EDITOR
    TasksUiUtil.openTask("http://eclipse.org/mylyn/test");
    assertEquals(3, activePage.getEditorReferences().length);
    editor = activePage.getEditorReferences()[2].getEditor(true);
    assertEquals(WebBrowserEditor.class, editor.getClass());
    assertEquals(WebBrowserEditorInput.class, editor.getEditorInput().getClass());
    assertEquals(
        "http://eclipse.org/mylyn/test",
        ((WebBrowserEditorInput) editor.getEditorInput()).getURL().toString());
    input = ((WebBrowserEditorInput) editor.getEditorInput());
    f = input.getClass().getDeclaredField("style");
    f.setAccessible(true);
    style = (Integer) f.get(input);
    assertTrue((style & BrowserUtil.NO_RICH_EDITOR) == 0);
  }
コード例 #10
0
  /**
   * Test method for {@link
   * org.talend.dataprofiler.core.CorePlugin#itemIsOpening(org.talend.core.model.properties.Item,
   * boolean)}.
   */
  @Test
  public void testItemIsOpeningItemBoolean() {
    try {
      CorePlugin cpMock = mock(CorePlugin.class);
      PowerMockito.mockStatic(CorePlugin.class);
      when(CorePlugin.getDefault()).thenReturn(cpMock);

      IWorkbench workbenchMock = mock(IWorkbench.class);
      when(cpMock.getWorkbench()).thenReturn(workbenchMock);

      IWorkbenchWindow workbenchWindowMock = mock(IWorkbenchWindow.class);
      when(workbenchMock.getActiveWorkbenchWindow()).thenReturn(workbenchWindowMock);

      IWorkbenchPage workbenchPageMock = mock(IWorkbenchPage.class);
      when(workbenchWindowMock.getActivePage()).thenReturn(workbenchPageMock);

      IEditorReference editorRefMock = mock(IEditorReference.class);
      IEditorReference[] editorRefMocks = new IEditorReference[] {editorRefMock};
      when(workbenchPageMock.getEditorReferences()).thenReturn(editorRefMocks);

      FileEditorInput fileEditorInputMock = mock(FileEditorInput.class);
      when(editorRefMock.getEditorInput()).thenReturn(fileEditorInputMock);

      String path1 = "/abc1"; // $NON-NLS-1$
      String path2 = "/abc2"; // $NON-NLS-1$

      IFile inputFileMock = mock(IFile.class);
      when(fileEditorInputMock.getFile()).thenReturn(inputFileMock);

      IPath inputFilePathMock = mock(IPath.class);
      when(inputFileMock.getFullPath()).thenReturn(inputFilePathMock);

      when(inputFilePathMock.toString()).thenReturn(path1);

      Item itemMock = mock(Item.class);
      Property propertyMock = mock(Property.class);
      when(itemMock.getProperty()).thenReturn(propertyMock);

      Resource resourceMock = mock(Resource.class);
      when(propertyMock.eResource()).thenReturn(resourceMock);

      IPath ipathMock = mock(IPath.class);
      PowerMockito.mockStatic(PropertyHelper.class);
      when(PropertyHelper.getItemPath(propertyMock)).thenReturn(ipathMock);
      when(ipathMock.toString()).thenReturn(path2);

      CorePlugin cp = new CorePlugin();
      assertFalse(cp.itemIsOpening(itemMock, false));
    } catch (PartInitException e) {
      fail(e.getMessage());
    }
  }
コード例 #11
0
 public static IDocument getDocFromEditor(IFile file) {
   IWorkbenchPage page = getActivePage();
   if (page == null) return null;
   IEditorReference[] ers = page.getEditorReferences();
   for (int i = 0; i < ers.length; i++) {
     IEditorInput input = getEditorInput(ers[i]);
     if (input == null) continue;
     IFile f = getFile(input);
     if (f == null || !f.equals(file)) continue;
     return getDocument(ers[i]);
   }
   return null;
 }
コード例 #12
0
ファイル: EditorUtility.java プロジェクト: CODINGLFQ/erlide
 public static Collection<IEditorPart> getAllErlangEditors() {
   final List<IEditorPart> result = Lists.newArrayList();
   final IWorkbench workbench = ErlideUIPlugin.getDefault().getWorkbench();
   for (final IWorkbenchWindow i : workbench.getWorkbenchWindows()) {
     for (final IWorkbenchPage j : i.getPages()) {
       for (final IEditorReference editorReference : j.getEditorReferences()) {
         final IEditorPart editorPart = editorReference.getEditor(false);
         if (editorPart instanceof ErlangEditor) {
           result.add(editorPart);
         }
       }
     }
   }
   return result;
 }
コード例 #13
0
ファイル: DLTKUIPlugin.java プロジェクト: earlyster/dltk.core
 public boolean preShutdown(IWorkbench workbench, boolean forced) {
   IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
   if (window != null) {
     IWorkbenchPage page = window.getActivePage();
     if (page != null) {
       IEditorReference[] references = page.getEditorReferences();
       for (int i = 0; i < references.length; i++) {
         IEditorPart editor = references[i].getEditor(false);
         if (editor != null) {
           closeEditor(page, editor);
         }
       }
     }
   }
   return true;
 }
コード例 #14
0
  private VdbEditor findEditorPart(final IWorkbenchPage page, IFile vdbFile) {
    // look through the open editors and see if there is one available for
    // this model file.
    final IEditorReference[] editors = page.getEditorReferences();
    for (int i = 0; i < editors.length; ++i) {

      final IEditorPart editor = editors[i].getEditor(false);
      if (editor instanceof VdbEditor) {
        final VdbEditor vdbEditor = (VdbEditor) editor;
        final IPath editorVdbPath = vdbEditor.getVdb().getName();
        if (vdbFile.getFullPath().equals(editorVdbPath)) return vdbEditor;
      }
    }

    return null;
  }
コード例 #15
0
  protected SVEditor findEditor(String path) {
    SVEditor ret = null;

    IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    for (IWorkbenchPage p : w.getPages()) {
      for (IEditorReference ed : p.getEditorReferences()) {
        if (ed.getName().endsWith(path)) {
          IEditorPart ed_p = ed.getEditor(true);
          if (ed_p instanceof SVEditor) {
            ret = (SVEditor) ed_p;
            break;
          }
        }
      }
    }
    return ret;
  }
コード例 #16
0
ファイル: PageLinkHelper.java プロジェクト: debabratahazra/DS
  /*
   * (non-Javadoc)
   *
   * @seeorg.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.
   * IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
   */
  @Override
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {

    // System.out.println("activateEditor: "+isDragActive);

    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }

    Object obj = aSelection.getFirstElement();
    if (obj instanceof IOfsModelResource) {
      IOfsModelResource ofsResource = (IOfsModelResource) obj;
      URI uri = ofsResource.getURI();
      String extension = uri.fileExtension();
      if (extension != null
          && StringUtils.contains(PageConstants.PAGE_DESIGNER_FILE_EXTENSIONS, extension, true)) {
        // check if an editor is alread open for the given uri.
        String filename = uri.lastSegment();
        String id =
            PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(filename).getId();
        for (IEditorReference editor : aPage.getEditorReferences()) {
          if (editor.getId().equals(id)) {
            try {
              IEditorInput eInput = editor.getEditorInput();
              if (eInput instanceof FileEditorInput) {
                FileEditorInput fInput = (FileEditorInput) eInput;
                if (filename.equals(fInput.getName())) {
                  if (isDragActive) {
                    // an editor is already open, simply return
                    // to avoid the activation of this editor.
                    isDragActive = false;
                    return;
                  }
                }
              }
            } catch (PartInitException ex) {
              // silently ignore
            }
          }
        }
      }
    }

    // editor not found
    super.activateEditor(aPage, aSelection);
  }
コード例 #17
0
  private void openedByBrowser(Item item, URL url) {
    if (url == null || item == null) {
      return;
    }

    WebBrowserEditorInput input = new WebBrowserEditorInput(url);
    // add for bug TDI-21189 at 2012-6-8,that a document exist is only opened one time in studio
    try {
      IWorkbenchPage page = getActivePage();
      IEditorReference[] iEditorReference = page.getEditorReferences();
      for (IEditorReference editors : iEditorReference) {
        if (WebBrowserEditor.WEB_BROWSER_EDITOR_ID.equals(editors.getId())) {
          IEditorPart iEditorPart = editors.getEditor(true);
          if (iEditorPart != null && iEditorPart instanceof WebBrowserEditor) {
            WebBrowserEditorInput webBrowserEditorInput =
                (WebBrowserEditorInput) iEditorPart.getEditorInput();
            if (webBrowserEditorInput != null && url.equals(webBrowserEditorInput.getURL())) {
              // page.activate(iEditorPart);
              iEditorPart.init(iEditorPart.getEditorSite(), webBrowserEditorInput);
              DocumentationUtil.setPartItemId(
                  (WebBrowserEditor) iEditorPart,
                  item.getProperty().getId(),
                  ERepositoryObjectType.getItemType(item));
              return;
            }
          }
        }
      }
      input.setName(item.getProperty().getLabel());
      input.setToolTipText(
          item.getProperty().getLabel() + " " + item.getProperty().getVersion()); // $NON-NLS-1$
      IEditorPart editorPart = page.openEditor(input, WebBrowserEditor.WEB_BROWSER_EDITOR_ID);
      if (editorPart != null && editorPart instanceof WebBrowserEditor) {
        DocumentationUtil.setPartItemId(
            (WebBrowserEditor) editorPart,
            item.getProperty().getId(),
            ERepositoryObjectType.getItemType(item));
      }
    } catch (PartInitException e) {
      MessageBoxExceptionHandler.process(e);
    }
  }
コード例 #18
0
  private void selectAndReveal(final ISelection selection) {
    // validate the input
    IWorkbenchPage page = fSite.getPage();
    if (page == null) return;

    // get all the view and editor parts
    List parts = new ArrayList();
    IWorkbenchPartReference refs[] = page.getViewReferences();
    for (int i = 0; i < refs.length; i++) {
      IWorkbenchPart part = refs[i].getPart(false);
      if (part != null) parts.add(part);
    }
    refs = page.getEditorReferences();
    for (int i = 0; i < refs.length; i++) {
      if (refs[i].getPart(false) != null) parts.add(refs[i].getPart(false));
    }

    Iterator itr = parts.iterator();
    while (itr.hasNext()) {
      IWorkbenchPart part = (IWorkbenchPart) itr.next();

      // get the part's ISetSelectionTarget implementation
      ISetSelectionTarget target = null;
      if (part instanceof ISetSelectionTarget) target = (ISetSelectionTarget) part;
      else target = (ISetSelectionTarget) part.getAdapter(ISetSelectionTarget.class);

      if (target != null) {
        // select and reveal resource
        final ISetSelectionTarget finalTarget = target;
        page.getWorkbenchWindow()
            .getShell()
            .getDisplay()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    finalTarget.selectReveal(selection);
                  }
                });
      }
    }
  }
コード例 #19
0
  /**
   * maximum display CheatSheetView.
   *
   * @param view
   */
  public void maxDisplayCheatSheetView(CheatSheetView view) {
    // ADD msjian TDQ-7407 2013-8-23: Only display the Cheat Sheet view on new startup of the studio
    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    activePage.setEditorAreaVisible(true);
    // activePage.resetPerspective();
    for (IViewReference ref : activePage.getViewReferences()) {
      if (view.equals(ref.getView(false))) {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MAXIMIZED);
        activePage.bringToTop(ref.getView(false));
      } else {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
      }
    }
    for (IEditorReference ref : activePage.getEditorReferences()) {
      activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
    }

    PrefUtil.getAPIPreferenceStore().setValue(this.getClass().getSimpleName(), true);
    setFirstTime(!PrefUtil.getAPIPreferenceStore().getBoolean(this.getClass().getSimpleName()));
    // TDQ-7407~
  }
コード例 #20
0
  @SuppressWarnings("unused")
  private IEditorPart getEditorFor(IFile file) {
    IWorkbenchPage page = getViewSite().getPage();

    for (IEditorReference editorReference : page.getEditorReferences()) {
      try {
        IEditorInput editorInput = editorReference.getEditorInput();

        if (editorInput instanceof IFileEditorInput) {
          IFileEditorInput input = (IFileEditorInput) editorInput;

          if (file.equals(input.getFile())) {
            return editorReference.getEditor(true);
          }
        }
      } catch (PartInitException pie) {
        // ignore
      }
    }

    return null;
  }
コード例 #21
0
  private static TypeHierarchyViewPart openInPerspective(IWorkbenchWindow window, IMemberInfo input)
      throws WorkbenchException, Exception {
    IWorkbench workbench = X10DTUIPlugin.getInstance().getWorkbench();
    // The problem is that the input element can be a working copy. So we first convert it to the
    // original element if
    // it exists.
    IMemberInfo perspectiveInput = input;

    if (input instanceof IMemberInfo) {
      if (!(input instanceof ITypeInfo)) {
        perspectiveInput = ((IMemberInfo) input).getDeclaringType();
      } else {
        perspectiveInput = input;
      }
    }
    ;
    IWorkbenchPage page =
        workbench.showPerspective(
            X10Constants.ID_HIERARCHYPERSPECTIVE,
            window,
            SearchUtils.getResource(perspectiveInput));

    TypeHierarchyViewPart part =
        (TypeHierarchyViewPart) page.findView(X10Constants.ID_TYPE_HIERARCHY);
    if (part != null) {
      part.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
    }
    part = (TypeHierarchyViewPart) page.showView(X10Constants.ID_TYPE_HIERARCHY);
    part.setInputElement(input);
    if (input instanceof IMemberInfo) {
      if (page.getEditorReferences().length == 0) {
        SearchUtils.openEditor(input);
      }
    }
    return part;
  }
コード例 #22
0
ファイル: ICEResourceView.java プロジェクト: nickstanish/ice
  /**
   * This operation overrides the ViewPart.createPartControl method to create and draw the
   * TreeViewer before registering it as a selection provider.
   *
   * @param parent The Composite used to create the TreeViewer.
   */
  @Override
  public void createPartControl(Composite parent) {

    // Create a TabFolder to manage tabs
    tabFolder = new TabFolder(parent, SWT.NONE);

    // Create pages (TabItems) for text files and images
    TabItem textTab = new TabItem(tabFolder, SWT.NONE, 0);
    textTab.setText("Files");
    TabItem imageTab = new TabItem(tabFolder, SWT.NONE, 1);
    imageTab.setText("Images");
    TabItem plotTab = new TabItem(tabFolder, SWT.NONE, 2);
    plotTab.setText("Plots");

    // Create the tool bar and buttons for the view
    createActions();

    // Initialize the TreeViewer
    resourceTreeViewer = new TreeViewer(tabFolder);
    // Create content and label providers
    initializeTreeViewer(resourceTreeViewer);
    // Register the tree to the tabs
    textTab.setControl(resourceTreeViewer.getControl());
    imageTab.setControl(resourceTreeViewer.getControl());
    // Register this view as a SelectionProvider
    getSite().setSelectionProvider(resourceTreeViewer);
    // Registered the view as a double click listener of the TreeViewer
    resourceTreeViewer.addDoubleClickListener(this);

    // Add a listener to catch tab selection changes.
    // NOTE: In Windows, this event is fired instantly, so this listener
    // needs to be declared after everything else is initialized!
    tabFolder.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            // If tabs are changed while playing, stop playing.
            if (playAction.isInPlayState()) {
              playAction.stop();
            }
            // Set the TreeViewer input to the selected tab
            setTreeContent(tabFolder.indexOf((TabItem) event.item));
          }
        });

    // Create the Table and table viewer for the Plot tab
    Table listTable = new Table(tabFolder, SWT.FLAT);
    DefaultEventTableViewer<VizResource> listTableViewer =
        new DefaultEventTableViewer<VizResource>(plotList, listTable, plotList);
    // Register the table control with the plot tab
    plotTab.setControl(listTable);

    // Check if there is currently an active ICEFormEditor. If so, update
    // the currently active editor and related UI pieces.
    IEditorPart activeEditor =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor != null && activeEditor instanceof ICEFormEditor) {
      if (activeEditor != editor) {
        setActiveEditor((ICEFormEditor) activeEditor);
      }
    } else {
      // Get a list of all the currently open editors
      IWorkbenchPage workbenchPage =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      IEditorReference[] editorRefs = workbenchPage.getEditorReferences();

      if (editorRefs != null && editorRefs.length > 0) {
        // Begin iterating through all the editors, looking for one
        // that's an ICEFormEditor
        for (IEditorReference e : editorRefs) {
          // If it's an ICEFormEditor, set it as the active editor
          if (e.getId().equals(ICEFormEditor.ID)) {
            setActiveEditor((ICEFormEditor) e.getEditor(false));
            break;
          }
        }
      }
    }

    // Register as a listener to the part service so that the view can
    // update when the active ICEFormEditor changes.
    IPartService partService = getSite().getWorkbenchWindow().getPartService();
    partService.addPartListener(this);

    return;
  }
コード例 #23
0
ファイル: TCFAnnotationManager.java プロジェクト: eclipse/tcf
 private void updateAnnotations(IWorkbenchWindow window, TCFNode node, Set<TCFAnnotation> set) {
   if (disposed) return;
   assert Thread.currentThread() == display.getThread();
   WorkbenchWindowInfo win_info = windows.get(window);
   if (win_info == null) return;
   Map<IEditorInput, IEditorPart> editors = new HashMap<IEditorInput, IEditorPart>();
   Map<IViewPart, ITCFDisassemblyPart> views = new HashMap<IViewPart, ITCFDisassemblyPart>();
   IWorkbenchPage page = window.getActivePage();
   if (page != null) {
     for (IEditorReference ref : page.getEditorReferences()) {
       IEditorPart editor = ref.getEditor(false);
       if (editor == null) continue;
       editors.put(editor.getEditorInput(), editor);
     }
     for (IViewReference ref : page.getViewReferences()) {
       IViewPart view = ref.getView(false);
       if (view == null) continue;
       ITCFDisassemblyPart disasm =
           (ITCFDisassemblyPart) view.getAdapter(ITCFDisassemblyPart.class);
       if (disasm != null) views.put(view, disasm);
     }
   }
   boolean flush_all =
       node == null
           || !views.keySet().equals(win_info.views.keySet())
           || !editors.equals(win_info.editors)
           || changed_launch_cfgs.contains(node.launch);
   win_info.views.clear();
   win_info.views.putAll(views);
   win_info.editors.clear();
   win_info.editors.putAll(editors);
   Iterator<TCFAnnotation> i = win_info.annotations.iterator();
   while (i.hasNext()) {
     TCFAnnotation a = i.next();
     if (!flush_all && set != null && set.remove(a)) continue;
     a.dispose();
     i.remove();
   }
   if (set != null) win_info.annotations.addAll(set);
   ISourcePresentation presentation = TCFModelPresentation.getDefault();
   // Disassembly views
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     for (ITCFDisassemblyPart disasm : views.values()) {
       IAnnotationModel ann_model = disasm.getAnnotationModel();
       if (ann_model == null) continue;
       if (a.models.contains(ann_model)) {
         ann_model.removeAnnotation(a);
         a.models.remove(ann_model);
       }
       Position p = disasm.getAddressPosition(a.addr);
       if (p == null) continue;
       if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
       ann_model.addAnnotation(a, p);
       a.models.add(ann_model);
     }
   }
   // Disassembly editor
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     IEditorPart editor = editors.get(TCFModel.DisassemblyEditorInput.INSTANCE);
     if (editor == null) continue;
     ITCFDisassemblyPart disasm =
         (ITCFDisassemblyPart) editor.getAdapter(ITCFDisassemblyPart.class);
     if (disasm == null) continue;
     IAnnotationModel ann_model = disasm.getAnnotationModel();
     if (ann_model == null) continue;
     if (a.models.contains(ann_model)) {
       ann_model.removeAnnotation(a);
       a.models.remove(ann_model);
     }
     Position p = disasm.getAddressPosition(a.addr);
     if (p == null) continue;
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
   // Source editors
   if (set == null) return;
   for (TCFAnnotation a : set) {
     if (a.area == null) continue;
     Object source_element = TCFSourceLookupDirector.lookup(node.launch, a.ctx, a.area);
     if (source_element == null) continue;
     IEditorInput editor_input = presentation.getEditorInput(source_element);
     IEditorPart editor = editors.get(editor_input);
     if (!(editor instanceof ITextEditor)) continue;
     IDocumentProvider doc_provider = ((ITextEditor) editor).getDocumentProvider();
     IAnnotationModel ann_model = doc_provider.getAnnotationModel(editor_input);
     if (ann_model == null) continue;
     IRegion region = null;
     try {
       doc_provider.connect(editor_input);
     } catch (CoreException e) {
     }
     try {
       IDocument document = doc_provider.getDocument(editor_input);
       if (document != null) region = document.getLineInformation(a.area.start_line - 1);
     } catch (BadLocationException e) {
     } finally {
       doc_provider.disconnect(editor_input);
     }
     if (region == null) continue;
     Position p = new Position(region.getOffset(), region.getLength());
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
 }
コード例 #24
0
  /**
   * Here, all the editors available will be gotten and searched (if possible).
   *
   * <p>Note that editors that are not in the workspace may not be searched (it should be possible
   * to do, but one may have to reimplement large portions of the search for that to work).
   */
  public static void findInOpenDocuments(
      final String searchText,
      final boolean caseSensitive,
      final boolean wholeWord,
      final boolean isRegEx,
      IStatusLineManager statusLineManager) {

    IWorkbenchWindow window = EditorUtils.getActiveWorkbenchWindow();
    if (window == null) {
      if (statusLineManager != null)
        statusLineManager.setErrorMessage("Active workbench window is null.");
      return;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
      if (statusLineManager != null) statusLineManager.setErrorMessage("Active page is null.");
      return;
    }
    IEditorReference editorsArray[] = activePage.getEditorReferences();

    final List<IFile> files = new ArrayList<IFile>();
    for (int i = 0; i < editorsArray.length; i++) {
      IEditorPart realEditor = editorsArray[i].getEditor(true);
      if (realEditor != null) {
        if (realEditor instanceof MultiPageEditorPart) {
          try {
            Method getPageCount = MultiPageEditorPart.class.getDeclaredMethod("getPageCount");
            getPageCount.setAccessible(true);
            Method getEditor = MultiPageEditorPart.class.getDeclaredMethod("getEditor", int.class);
            getEditor.setAccessible(true);

            Integer pageCount = (Integer) getPageCount.invoke(realEditor);
            for (int j = 0; j < pageCount; j++) {
              IEditorPart part = (IEditorPart) getEditor.invoke(realEditor, j);
              if (part != null) {
                IEditorInput input = part.getEditorInput();
                if (input != null) {
                  IFile file = (IFile) input.getAdapter(IFile.class);
                  if (file != null) {
                    files.add(file);
                  }
                }
              }
            }
          } catch (Throwable e1) {
            // Log it but keep going on.
            Log.log(e1);
          }

        } else {
          IEditorInput input = realEditor.getEditorInput();
          if (input != null) {
            IFile file = (IFile) input.getAdapter(IFile.class);
            if (file != null) {
              files.add(file);
            } else {
              // it has input, but it's not adaptable to an IFile!
              if (statusLineManager != null)
                statusLineManager.setMessage(
                    "Warning: Editors not in the workspace cannot be searched.");
              // but we keep on going...
            }
          }
        }
      }
    }

    if (files.size() == 0) {
      if (statusLineManager != null)
        statusLineManager.setMessage(
            "No file was found to perform the search (editors not in the workspace cannot be searched).");
      return;
    }

    try {
      ISearchQuery query =
          TextSearchQueryProvider.getPreferred()
              .createQuery(
                  new TextSearchInput() {

                    public boolean isRegExSearch() {
                      return isRegEx;
                    }

                    public boolean isCaseSensitiveSearch() {
                      return caseSensitive;
                    }

                    public String getSearchText() {
                      return searchText;
                    }

                    public FileTextSearchScope getScope() {
                      return FileTextSearchScope.newSearchScope(
                          files.toArray(new IResource[files.size()]), new String[] {"*"}, true);
                    }
                  });
      NewSearchUI.runQueryInBackground(query);
    } catch (CoreException e1) {
      Log.log(e1);
    }
  }
コード例 #25
0
 public void run() {
   // TODO support uml files to be opened
   Shell shell = Display.getCurrent().getActiveShell();
   Collection<IFile> files = new HashSet<IFile>();
   for (IWorkbenchWindow w : PlatformUI.getWorkbench().getWorkbenchWindows()) {
     for (IWorkbenchPage p : w.getPages()) {
       for (IEditorReference e : p.getEditorReferences()) {
         try {
           if (e.getEditorInput() instanceof IFileEditorInput) {
             IFileEditorInput editorInput = (IFileEditorInput) e.getEditorInput();
             if (editorInput.getFile().getParent().findMember("opaeum.properties") != null) {
               OpaeumEclipseContext ctx =
                   OpaeumEclipseContext.findOrCreateContextFor(editorInput.getFile().getParent());
               for (IResource r : editorInput.getFile().getParent().members()) {
                 if (r.getName().endsWith(".uml")) {
                   OpenUmlFile ouf = ctx.getOpenUmlFileFor((IFile) r);
                   if (ouf != null && canReverseInto(ouf)) {
                     files.add((IFile) r);
                   }
                 }
               }
             }
           }
         } catch (PartInitException e1) {
           e1.printStackTrace();
         } catch (CoreException e2) {
           e2.printStackTrace();
         }
       }
     }
   }
   ElementListSelectionDialog dialog =
       new ElementListSelectionDialog(
           shell,
           new LabelProvider() {
             @Override
             public String getText(Object element) {
               IFile file = (IFile) element;
               return file.getProject().getName() + "/" + file.getProjectRelativePath();
             }
           });
   dialog.setElements(files.toArray());
   dialog.setTitle("Models in Workspace");
   dialog.setMessage("Select the targetmodel:");
   dialog.open();
   if (dialog.getFirstResult() != null) {
     IFile file = (IFile) dialog.getFirstResult();
     OpaeumEclipseContext ctx = OpaeumEclipseContext.getContextFor(file.getParent());
     if (ctx != null) {
       final OpenUmlFile ouf = ctx.getOpenUmlFileFor(file);
       if (ouf != null) {
         ouf.suspend();
         setSelectedEditor(file.getName());
         ouf.getEditingDomain().getCommandStack().execute(buildCommand(ouf.getModel()));
         ouf.resumeAndCatchUp();
       }
     }
     try {
       file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
     } catch (CoreException e) {
       e.printStackTrace();
     }
   }
 }