@Override
 public void apply(IDocument document) {
   try {
     ITranslationUnit unit = getTranslationUnit();
     IEditorPart part = null;
     if (unit.getResource().exists()) {
       boolean canEdit = performValidateEdit(unit);
       if (!canEdit) {
         return;
       }
       part = EditorUtility.isOpenInEditor(unit);
       if (part == null) {
         part = EditorUtility.openInEditor(unit);
         if (part != null) {
           document =
               CUIPlugin.getDefault().getDocumentProvider().getDocument(part.getEditorInput());
         }
       }
       IWorkbenchPage page = CUIPlugin.getActivePage();
       if (page != null && part != null) {
         page.bringToTop(part);
       }
       if (part != null) {
         part.setFocus();
       }
     }
     performChange(part, document);
   } catch (CoreException e) {
     ExceptionHandler.handle(
         e,
         CorrectionMessages.TUCorrectionProposal_error_title,
         CorrectionMessages.TUCorrectionProposal_error_message);
   }
 }
  @Override
  public void selectionChanged(SelectionChangedEvent event) {
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection) {

      // If the selection event source is different from the active part,
      // that means the selection change has not been triggered by a user
      // action. In that case we do nothing to avoid loops.
      if (event.getSource() != getActivePartSource()) {
        return;
      }

      // If the selection come from the navigator, we select the
      // corresponding representations elements.
      if (event.getSource().equals(navigator.getCommonViewer())) {
        IWorkbenchPage page = EclipseUIUtil.getActivePage();
        IEditorPart activeEditor = page.getActiveEditor();
        if (activeEditor instanceof DialectEditor) {
          DialectEditor dialectEditor = (DialectEditor) activeEditor;
          page.bringToTop(dialectEditor);
          selectRepresentationElements(selection, dialectEditor);
        }
      } else {
        Set<EObject> targets = getTargetsFromSelection((IStructuredSelection) selection);
        if (!targets.isEmpty()) {
          navigator.selectReveal(new StructuredSelection(targets.toArray()));
        }
      }
    }
  }
Пример #3
0
  public JavaEditor openJavaEditor(IJavaElement javaElement) {
    IEditorPart part = EditorUtility.isOpenInEditor(javaElement);
    if (part == null) {
      try {
        part = JavaUI.openInEditor(javaElement);
      } catch (PartInitException e) {
        // ignore
      } catch (JavaModelException e) {
        // ignore
      }
    }

    IWorkbenchPage page = JavaPlugin.getActivePage();
    if (page != null && part != null) {
      page.bringToTop(part);
    }
    if (part != null) {
      part.setFocus();
    }
    if (part instanceof JavaEditor) {
      return (JavaEditor) part;
    }

    return null;
  }
  /**
   * 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;
  }
Пример #5
0
 /**
  * Links to editor (if option enabled)
  *
  * @param selection the selection
  */
 private void linkToEditor(ISelection selection) {
   Object obj = SelectionUtil.getSingleElement(selection);
   if (obj != null) {
     IEditorPart part = EditorUtility.isOpenInEditor(obj);
     if (part != null) {
       IWorkbenchPage page = getSite().getPage();
       page.bringToTop(part);
       if (obj instanceof IJavaElement) EditorUtility.revealInEditor(part, (IJavaElement) obj);
     }
   }
 }
Пример #6
0
 /**
  * Links to editor (if option enabled)
  *
  * @param selection the selection
  */
 protected void linkToEditor(IStructuredSelection selection) {
   if (!isActivePart()) return;
   Object obj = selection.getFirstElement();
   if (selection.size() == 1) {
     IEditorPart part = EditorUtil.isOpenInEditor(obj);
     if (part != null) {
       IWorkbenchPage page = getSite().getPage();
       page.bringToTop(part);
     }
   }
 }
  /**
   * Links to editor (if option enabled)
   *
   * @param selection the selection
   */
  private void linkToEditor(IStructuredSelection selection) {
    Object obj = selection.getFirstElement();

    if (selection.size() == 1) {
      IEditorPart part = EditorUtility.isOpenInEditor(obj);
      if (part != null) {
        IWorkbenchPage page = getSite().getPage();
        page.bringToTop(part);
        if (obj instanceof IModelElement) EditorUtility.revealInEditor(part, (IModelElement) obj);
      }
    }
  }
Пример #8
0
  /** @generated */
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }
    if (false == aSelection.getFirstElement() instanceof MIDAbstractNavigatorItem) {
      return;
    }

    MIDAbstractNavigatorItem abstractNavigatorItem =
        (MIDAbstractNavigatorItem) aSelection.getFirstElement();
    View navigatorView = null;
    if (abstractNavigatorItem instanceof MIDNavigatorItem) {
      navigatorView = ((MIDNavigatorItem) abstractNavigatorItem).getView();
    } else if (abstractNavigatorItem instanceof MIDNavigatorGroup) {
      MIDNavigatorGroup navigatorGroup = (MIDNavigatorGroup) abstractNavigatorItem;
      if (navigatorGroup.getParent() instanceof MIDNavigatorItem) {
        navigatorView = ((MIDNavigatorItem) navigatorGroup.getParent()).getView();
      } else if (navigatorGroup.getParent() instanceof IAdaptable) {
        navigatorView = (View) ((IAdaptable) navigatorGroup.getParent()).getAdapter(View.class);
      }
    }
    if (navigatorView == null) {
      return;
    }
    IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
    IEditorPart editor = aPage.findEditor(editorInput);
    if (editor == null) {
      return;
    }
    aPage.bringToTop(editor);
    if (editor instanceof DiagramEditor) {
      DiagramEditor diagramEditor = (DiagramEditor) editor;
      ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
      EObject selectedView =
          diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true);
      if (selectedView == null) {
        return;
      }
      GraphicalViewer graphicalViewer =
          (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
      EditPart selectedEditPart =
          (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView);
      if (selectedEditPart != null) {
        graphicalViewer.select(selectedEditPart);
      }
    }
  }
Пример #9
0
 public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
   if (aSelection == null || aSelection.isEmpty()) {
     return;
   }
   Object element = aSelection.getFirstElement();
   if (element instanceof FileSystemObject) {
     FileSystemObject file = (FileSystemObject) element;
     IFileStore fileStore = file.getFileStore();
     try {
       IEditorPart editorPart =
           aPage.findEditor(
               UniformFileStoreEditorInputFactory.getUniformEditorInput(
                   fileStore, new NullProgressMonitor()));
       aPage.bringToTop(editorPart);
     } catch (CoreException e) {
       IOUIPlugin.logError(e);
     }
   }
 }
Пример #10
0
  @Override
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    // check if something has been selected
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }

    // check if selection can be handled
    if (aSelection.getFirstElement() instanceof PSNavigatorItem == false) {
      return;
    }

    EObject item = ((PSNavigatorItem) aSelection.getFirstElement()).getItem();

    // try to get correct editor input
    IEditorPart editor = aPage.findEditor(getEditorInput(item));
    if (editor == null) {
      return;
    }

    aPage.bringToTop(editor);
    // if (editor instanceof DiagramEditor)
    // {
    // DiagramEditor diagramEditor = (DiagramEditor) editor;
    // ResourceSet diagramEditorResourceSet = diagramEditor
    // .getEditingDomain().getResourceSet();
    // EObject selectedView = diagramEditorResourceSet.getEObject(
    // EcoreUtil.getURI(item), true);
    // if (selectedView == null)
    // {
    // return;
    // }
    // GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor
    // .getAdapter(GraphicalViewer.class);
    // EditPart selectedEditPart = (EditPart) graphicalViewer
    // .getEditPartRegistry().get(selectedView);
    // if (selectedEditPart != null)
    // {
    // graphicalViewer.select(selectedEditPart);
    // }
    // }
  }
Пример #11
0
 /* (non-javadoc)
  * This action will try to launch the cheat sheet view and populate
  * it with the content specified either in the URL or the content
  * file specified in the cheatsheetContent extension point
  * for the cheat sheet with the id passed to this action.
  * @see IAction#run()
  */
 public void run() {
   // RAP [if] Help system not supported
   //		Shell shell = Display.getDefault().getActiveShell();
   //		// are we in a dialog that can show a cheat sheet?
   //		if (shell != null && !shell.isFocusControl() && shell.getData() instanceof TrayDialog) {
   //			TrayDialog dialog = (TrayDialog)shell.getData();
   //			HelpTray tray = (HelpTray)dialog.getTray();
   //			if (tray == null) {
   //				tray = new HelpTray();
   //				dialog.openTray(tray);
   //			}
   //			ReusableHelpPart helpPart = tray.getHelpPart();
   //			IHelpPartPage page = helpPart.createPage(CheatSheetHelpPart.ID, null, null);
   //			page.setVerticalSpacing(0);
   //			page.setHorizontalMargin(0);
   //			CheatSheetElement contentElement =
   // CheatSheetRegistryReader.getInstance().findCheatSheet(id);
   //			helpPart.addPart(CheatSheetHelpPart.ID, new
   // CheatSheetHelpPart(helpPart.getForm().getForm().getBody(), helpPart.getForm().getToolkit(),
   // page.getToolBarManager(), contentElement, new DefaultStateManager()));
   //			page.addPart(CheatSheetHelpPart.ID, true);
   //			helpPart.addPage(page);
   //			helpPart.showPage(CheatSheetHelpPart.ID);
   //		}
   //		else {
   CheatSheetView view = ViewUtilities.showCheatSheetView();
   if (view == null) {
     return;
   }
   // Depending on which constructor was used open the cheat sheet view from a
   // URL, an XML string or based on the id
   if (url != null) {
     view.setInput(id, name, url);
   } else if (xml != null) {
     view.setInputFromXml(id, name, xml, basePath);
   } else {
     view.setInput(id);
   }
   IWorkbenchPage page = view.getSite().getWorkbenchWindow().getActivePage();
   page.bringToTop(view);
   //		}
 }
Пример #12
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
   */
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }

    Object firstElement = aSelection.getFirstElement();

    // if it is a python element, let's first get the actual object for finding the editor
    if (firstElement instanceof IWrappedResource) {
      IWrappedResource resource = (IWrappedResource) firstElement;
      firstElement = resource.getActualObject();
    }

    // and now, if it is really a file...
    if (firstElement instanceof IFile) {

      // ok, let's check if the active editor is already the selection, because although the
      // findEditor(editorInput) method
      // may return an editor for the correct file, we may have multiple editors for the same file,
      // and if the current
      // editor is already correct, we don't want to change it
      // @see bug:
      // https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796
      IEditorPart activeEditor = aPage.getActiveEditor();
      if (activeEditor != null) {
        IEditorInput editorInput = activeEditor.getEditorInput();
        IFile currFile = (IFile) editorInput.getAdapter(IFile.class);
        if (currFile != null && currFile.equals(firstElement)) {
          return; // the current editor is already the active editor.
        }
      }

      // if we got here, the active editor is not a match, so, let's find one and show it.
      IEditorPart editor = null;
      IEditorInput fileInput = new FileEditorInput((IFile) firstElement);
      if ((editor = aPage.findEditor(fileInput)) != null) {
        aPage.bringToTop(editor);
      }
    }
  }
  /**
   * 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~
  }
  @Override
  public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {

    final Object element = selection.getFirstElement();
    final IEditorPart part = EditorUtility.isOpenInEditor(element);
    if (part != null) {
      page.bringToTop(part);
      if (element instanceof IErlElement) {
        EditorUtility.revealInEditor(part, (IErlElement) element);
      }
    }

    // if (selection == null || selection.isEmpty()) {
    // return;
    // }
    //
    // final Object firstElement = selection.getFirstElement();
    //
    // if (firstElement instanceof IErlElement) {
    // final IErlElement e = (IErlElement) firstElement;
    //
    // }
    // // if it is an erlang element, let's first get the actual object for
    // // finding the editor
    //
    // // and now, if it is really a file...
    // if (firstElement instanceof IFile) {
    // final IEditorInput fileInput = new FileEditorInput(
    // (IFile) firstElement);
    // IEditorPart editor = null;
    // if ((editor = page.findEditor(fileInput)) != null) {
    // page.bringToTop(editor);
    // }
    // }

  }