public boolean isReadOnly() {
    XSDSchema xsdSchema = null;
    try {
      IEditorPart editorPart = null;
      IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
          editorPart = page.getActiveEditor();
        }
      }
      if (target instanceof XSDConcreteComponent) {
        xsdSchema = ((XSDConcreteComponent) target).getSchema();
      }
      if (editorPart == null) {
        return fallBackCheckIsReadOnly();
      }

      XSDSchema editorSchema = (XSDSchema) editorPart.getAdapter(XSDSchema.class);
      if (xsdSchema != null && xsdSchema == editorSchema) {
        return false;
      } else {
        return fallBackCheckIsReadOnly();
      }
    } catch (Exception e) {

    }
    return true;
  }
  private ModelSet getModelSet(Object receiver) {
    if (receiver instanceof IWorkbenchPart) {
      try {

        /* First, retrieve the ModelSet from the Active Part (e.g. ActiveEditor, ModelExplorer, ...) */
        IWorkbenchPart currentPart = (IWorkbenchPart) receiver;
        ServicesRegistry servicesRegistry =
            (ServicesRegistry) currentPart.getAdapter(ServicesRegistry.class);

        if (servicesRegistry != null) {
          return ServiceUtils.getInstance().getModelSet(servicesRegistry);
        }

        /* If not found, retrieve the ModelSet from the Active Editor */
        IEditorPart activeEditor = EditorHelper.getCurrentEditor();
        if (activeEditor != null) {
          servicesRegistry = (ServicesRegistry) activeEditor.getAdapter(ServicesRegistry.class);

          if (servicesRegistry != null) {
            return ServiceUtils.getInstance().getModelSet(servicesRegistry);
          }
        }
      } catch (Exception ex) {
        return null; // NPE (getActiveEditor) or ServiceException (Service registry cannot be
                     // found). In both cases, we just don't handle the event. Fail silently.
      }
    }

    return null;
  }
  @Override
  public void execute(String newText) throws CoreException {

    if (newText.isEmpty()) {
      if (getModel().getText() != null) {
        EnquiryTranslationRemoveCommand removeCmd = new EnquiryTranslationRemoveCommand(getModel());
        removeCmd.execute(newText);
      }
      return;
    }
    if (newText.equals(getModel().getText())) {
      // do nothing if text is the same.
      return;
    }

    IEditorPart editorPart = getActiveEditorPart();
    if (editorPart != null) {

      // Extract useful parameters needed for the command
      IWorkbenchPartSite site = editorPart.getSite();

      // Invoke the command
      IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
      ICommandService commandService = (ICommandService) site.getService(ICommandService.class);

      CommandStack commandStack = (CommandStack) editorPart.getAdapter(CommandStack.class);

      try {

        // Get the command and assign values to parameters
        Command command = commandService.getCommand(EDIT_COMMAND_ID);
        Parameterization parameter = new Parameterization(command.getParameter("text"), newText);
        ParameterizedCommand parmCommand =
            new ParameterizedCommand(command, new Parameterization[] {parameter});

        // Prepare the evaluation context
        IEvaluationContext ctx = handlerService.getCurrentState();
        ctx.addVariable("model", getModel());
        ctx.addVariable("commandStack", commandStack);

        // Execute the command
        handlerService.executeCommandInContext(parmCommand, null, ctx);

      } catch (Exception ex) {
        IStatus status =
            new Status(
                IStatus.ERROR,
                Activator.PLUGIN_ID,
                "Error while executing command to update translation",
                ex);
        throw new CoreException(status);
      }
    } else {
      /** @TODO log warn no active editorPart, should never occur */
    }
  }
示例#4
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor) textEditor = (ITextEditor) editor;
    else {
      Object o = editor.getAdapter(ITextEditor.class);
      if (o != null) textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
      IDocument document =
          textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());

      if (document != null) {
        // get current text selection
        ITextSelection textSelection = getCurrentSelection(textEditor);

        // If there is alternating or more then one block in the text
        // selection, action is aborted !
        if (isMoreThanOneContextBlockSelected(document, textSelection)) {
          // displayCommentActinosErrorDialog(editor);
          // return null;
          org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
              addBlockCommentHandlerWST =
                  new org.eclipse.wst.sse.ui.internal.handlers
                      .AddBlockCommentHandler(); // org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
          return addBlockCommentHandlerWST.execute(event);
        }

        if (textSelection.isEmpty()) {
          return null;
        }
        if (document instanceof IStructuredDocument) {
          int selectionOffset = textSelection.getOffset();
          IStructuredDocument sDoc = (IStructuredDocument) document;
          IStructuredDocumentRegion sdRegion = sDoc.getRegionAtCharacterOffset(selectionOffset);
          ITextRegion textRegion = sdRegion.getRegionAtCharacterOffset(selectionOffset);

          ITextRegionCollection container = sdRegion;

          if (textRegion instanceof ITextRegionContainer) {
            container = (ITextRegionContainer) textRegion;
            textRegion = container.getRegionAtCharacterOffset(selectionOffset);
          }
          if (textRegion.getType() == PHPRegionContext.PHP_CONTENT) {
            processAction(textEditor, document, textSelection);
          } else {
            org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
                addBlockCommentHandlerWST =
                    new org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
            return addBlockCommentHandlerWST.execute(event);
          }
        }
      }
    }
    return null;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
  */
 public Object getAdapter(Class key) {
   Object adapter = null;
   if (key.equals(IShowInTarget.class)) {
     adapter = new ShowInTarget();
   } else if (key.equals(IShowInSource.class)) {
     adapter = new ShowInSource();
   } else if (key.equals(IShowInTargetList.class) && fEditor != null) {
     adapter = fEditor.getAdapter(key);
   }
   return adapter;
 }
示例#6
0
 /**
  * Diagramモデルを返却する.
  *
  * @return
  */
 public static final RootModel getActiveDiagramModel() {
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   if (window != null) {
     IWorkbenchPage page = window.getActivePage();
     if (page != null) {
       IEditorPart editor = window.getActivePage().getActiveEditor();
       return (RootModel) editor.getAdapter(RootModel.class);
     }
   }
   return null;
 }
 protected GFFigureCanvas getGFCanvas() {
   IEditorReference reference = getGefEditor().getReference();
   final IEditorPart editor = reference.getEditor(true);
   GraphicalViewer graphicalViewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class);
   final Control control = graphicalViewer.getControl();
   if (control instanceof GFFigureCanvas) {
     GFFigureCanvas c = (GFFigureCanvas) control;
     return c;
   }
   return null;
 }
 /** @generated */
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IEditorPart diagramEditor = HandlerUtil.getActiveEditorChecked(event);
   Shell shell = diagramEditor.getEditorSite().getShell();
   assert diagramEditor instanceof DiagramEditor;
   TransactionalEditingDomain editingDomain =
       (TransactionalEditingDomain) diagramEditor.getAdapter(EditingDomain.class);
   org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog loadResourceDialog =
       new org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog(
           shell, editingDomain);
   loadResourceDialog.open();
   return null;
 }
  /**
   * returns the resource that is active in the current editor, this is used for the {@link
   * XtextPropertyDescriptor}s context resource to enable scoping to elements outside the text block
   */
  protected Resource getActiveEditorResource() {
    IEditorPart editor = ActiveEditorTracker.getLastActiveEditor();

    EditingDomain domain = null;
    if (editor instanceof IEditingDomainProvider) {
      domain = ((IEditingDomainProvider) editor).getEditingDomain();
    } else if (editor.getAdapter(IEditingDomainProvider.class) != null) {
      domain =
          ((IEditingDomainProvider) editor.getAdapter(IEditingDomainProvider.class))
              .getEditingDomain();
    } else if (editor.getAdapter(EditingDomain.class) != null) {
      domain = (EditingDomain) editor.getAdapter(EditingDomain.class);
    }
    if (domain == null) {
      return null;
    }

    EList<Resource> resources = domain.getResourceSet().getResources();

    return resources.get(0); // always take the first resource ...
  }
  public CjBreakpointRulerAction(
      IVerticalRulerInfo ruler, ITextEditor editor, IEditorPart editorPart) {

    // super(ActionMessages.getString("ManageBreakpointRulerAction.label") );
    // super(ActionMessages.ManageBreakpointRulerAction_label);
    // This message may not make sense FIXME
    super(ActionMessages.JavaBreakpointPropertiesRulerAction_Breakpoint__Properties_1);

    fRuler = ruler;
    fTextEditor = editor;
    fStatusLine = (IEditorStatusLine) editorPart.getAdapter(IEditorStatusLine.class);
    fBreakpointAdapter = new CjToggleBreakpointAdapter();
  }
示例#11
0
  protected SVOutlinePage getOutlineView(IEditorPart editor) throws PartInitException {
    IViewPart outline_v =
        editor.getSite().getPage().showView("org.eclipse.ui.views.ContentOutline");
    assertNotNull(outline_v);

    while (Display.getDefault().readAndDispatch()) {}

    Object ret = editor.getAdapter(IContentOutlinePage.class);

    assertTrue(ret instanceof SVOutlinePage);

    return (SVOutlinePage) ret;
  }
示例#12
0
  private void updatePreview(boolean force) {
    if (swtXmlEditorPart == null) {
      setContent(null);
      return;
    }

    IDocument doc = (IDocument) swtXmlEditorPart.getAdapter(IDocument.class);
    IDocumentExtension4 document = (IDocumentExtension4) doc;
    if (force || document.getModificationStamp() != lastPreviewModificationStamp) {
      try {
        ResizableComposite resizableComposite = null;
        Composite newComposite;
        Composite swtXmlComposite;

        if (resizeAction.isChecked()) {
          resizableComposite = new ResizableComposite(container);
          newComposite = resizableComposite;
          swtXmlComposite = resizableComposite.getResizeableComposite();
        } else {
          newComposite = swtXmlComposite = new Composite(container, SWT.None);
        }

        IEditorInput editorInput = swtXmlEditorPart.getEditorInput();
        ILocationProvider locationProvider =
            (ILocationProvider) editorInput.getAdapter(ILocationProvider.class);

        File file =
            (locationProvider == null) ? null : locationProvider.getPath(editorInput).toFile();
        FileEditorInput input = (FileEditorInput) editorInput;
        SwtXmlParser parser =
            new SwtXmlParser(
                swtXmlComposite, new PreviewResource(getProjectRootDir(input), file, doc), null);
        parser.parse();
        setContent(newComposite);

        if (resizableComposite != null) {
          resizableComposite.resetSize();
        }
      } catch (Exception e) {
        Activator.getDefault()
            .getLog()
            .log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
        setContent(new ErrorComposite(container, SWT.NONE, e));
      } finally {
        lastPreviewModificationStamp = document.getModificationStamp();
        container.layout();
      }
    }
  }
示例#13
0
  /**
   * 執行Quick Fix變更
   *
   * @param activeEditor
   * @param document
   * @throws CoreException
   */
  private void performChange(IEditorPart activeEditor, IDocument document, ASTRewrite rewrite)
      throws CoreException {
    Change change = null;
    IRewriteTarget rewriteTarget = null;
    try {
      change = getChange(actRoot, rewrite);
      if (change != null) {
        if (document != null) {
          LinkedModeModel.closeAllModels(document);
        }
        if (activeEditor != null) {
          rewriteTarget = (IRewriteTarget) activeEditor.getAdapter(IRewriteTarget.class);
          if (rewriteTarget != null) {
            rewriteTarget.beginCompoundChange();
          }
        }

        change.initializeValidationData(new NullProgressMonitor());
        RefactoringStatus valid = change.isValid(new NullProgressMonitor());
        if (valid.hasFatalError()) {
          IStatus status =
              new Status(
                  IStatus.ERROR,
                  JavaPlugin.getPluginId(),
                  IStatus.ERROR,
                  valid.getMessageMatchingSeverity(RefactoringStatus.FATAL),
                  null);
          throw new CoreException(status);
        } else {
          IUndoManager manager = RefactoringCore.getUndoManager();
          manager.aboutToPerformChange(change);
          Change undoChange = change.perform(new NullProgressMonitor());
          manager.changePerformed(change, true);
          if (undoChange != null) {
            undoChange.initializeValidationData(new NullProgressMonitor());
            manager.addUndo("Quick Undo", undoChange);
          }
        }
      }
    } finally {
      if (rewriteTarget != null) {
        rewriteTarget.endCompoundChange();
      }

      if (change != null) {
        change.dispose();
      }
    }
  }
 public boolean isShownInEditor(Match match, IEditorPart editor) {
   Object element = match.getElement();
   if (element instanceof IDOMNode) {
     // DOMNode matched
     IDOMNode node = (IDOMNode) element;
     IStructuredModel editorModel = (IStructuredModel) editor.getAdapter(IStructuredModel.class);
     if (editorModel != null) {
       // Returns true if found node belong to the current XML editor
       // which
       // has launched the search and false otherwise.
       return editorModel.equals(node.getModel());
     }
   }
   return false;
 }
  private void initialize(ExecutionEvent event, IModelElement element)
      throws InvalidElementException {

    editorPart = HandlerUtil.getActiveEditor(event);
    textEditor = null;
    if (editorPart instanceof PHPStructuredEditor) textEditor = (PHPStructuredEditor) editorPart;
    else {
      Object o = editorPart.getAdapter(ITextEditor.class);
      if (o != null) textEditor = (PHPStructuredEditor) o;
    }

    document = textEditor.getDocument();

    setupOptions();
  }
 /**
  * Returns whether the Smart Insert Mode is selected.
  *
  * @return <code>true</code> if the Smart Insert Mode is selected
  * @since 3.7
  */
 private boolean isSmartInsertMode() {
   IWorkbenchPage page = JavaPlugin.getActivePage();
   if (page != null) {
     IEditorPart part = page.getActiveEditor();
     if (part instanceof ITextEditorExtension3) {
       ITextEditorExtension3 extension = (ITextEditorExtension3) part;
       return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT;
     } else if (part != null && EditorUtility.isCompareEditorInput(part.getEditorInput())) {
       ITextEditorExtension3 extension =
           (ITextEditorExtension3) part.getAdapter(ITextEditorExtension3.class);
       if (extension != null)
         return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT;
     }
   }
   return false;
 }
示例#17
0
 @SuppressWarnings("rawtypes")
 @Override
 public Object getAdapter(Class adapter) {
   if (contentOutlineProvider != null) {
     return contentOutlineProvider.getAdapter(adapter);
   } else if (IContentOutlinePage.class.equals(adapter)) {
     IFormPage[] pages = getPages();
     for (IFormPage page : pages) {
       Object outlinePage = page.getAdapter(adapter);
       if (outlinePage != null) {
         return outlinePage;
       }
     }
   }
   return super.getAdapter(adapter);
 }
  protected void activateDirectEdit() {
    if (getWorkbenchPart() instanceof IEditorPart) {
      try {
        IEditorPart owningEditor = (IEditorPart) getWorkbenchPart();
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchPart part = workbench.getActiveWorkbenchWindow().getActivePage().getActivePart();
        Object object = owningEditor.getAdapter(GraphicalViewer.class);
        if (object instanceof AbstractEditPartViewer) {
          AbstractEditPartViewer viewer = (AbstractEditPartViewer) object;
          Object obj = viewer.getSelectedEditParts().get(0);
          doEdit(obj, part);
        }
      } catch (Exception e) {

      }
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {

    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win.getActivePage();
    IEditorPart activeEditor = page.getActiveEditor();
    if (activeEditor == null) {
      return null;
    }
    XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
    if (xtextEditor != null) {
      IXtextDocument iXTextDoc = xtextEditor.getDocument();
      iXTextDoc.modify(
          new IUnitOfWork.Void() {
            @Override
            public void process(Object state) throws Exception {
              EObject rootObject = ((Resource) state).getContents().get(0);
              if (rootObject instanceof AadlPackage) {
                AadlPackage pkg = (AadlPackage) rootObject;
                List<PackageSection> pkgSections = new ArrayList<PackageSection>();
                if (pkg.getOwnedPublicSection() != null) {
                  pkgSections.add(pkg.getOwnedPublicSection());
                }
                if (pkg.getOwnedPrivateSection() != null) {
                  pkgSections.add(pkg.getOwnedPrivateSection());
                }
                for (PackageSection pkgSection : pkgSections) {
                  organizeWithClauses(pkgSection);
                }
              } else if (rootObject instanceof PropertySet) {
                PropertySet propSet = (PropertySet) rootObject;
                organizeWithClauses(propSet);
              }
            }
          });
    }
    return null;
  }
 protected Object getEditorSchema() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
   IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
   return editorPart.getAdapter(XSDSchema.class);
 }
示例#21
0
 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);
   }
 }
示例#22
0
  private void run(Shell shell, IType type) throws CoreException {
    final OverrideMethodDialog dialog = new OverrideMethodDialog(shell, fEditor, type, false);
    if (!dialog.hasMethodsToOverride()) {
      MessageDialog.openInformation(
          shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found);
      notifyResult(false);
      return;
    }
    if (dialog.open() != Window.OK) {
      notifyResult(false);
      return;
    }

    final Object[] selected = dialog.getResult();
    if (selected == null) {
      notifyResult(false);
      return;
    }

    ArrayList<IMethodBinding> methods = new ArrayList<IMethodBinding>();
    for (int i = 0; i < selected.length; i++) {
      Object elem = selected[i];
      if (elem instanceof IMethodBinding) {
        methods.add((IMethodBinding) elem);
      }
    }
    IMethodBinding[] methodToOverride = methods.toArray(new IMethodBinding[methods.size()]);

    final IEditorPart editor = JavaUI.openInEditor(type.getCompilationUnit());
    final IRewriteTarget target =
        editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null;
    if (target != null) target.beginCompoundChange();
    try {
      CompilationUnit astRoot = dialog.getCompilationUnit();
      final ITypeBinding typeBinding = ASTNodes.getTypeBinding(astRoot, type);
      int insertPos = dialog.getInsertOffset();

      AddUnimplementedMethodsOperation operation =
          (AddUnimplementedMethodsOperation)
              createRunnable(
                  astRoot, typeBinding, methodToOverride, insertPos, dialog.getGenerateComment());
      IRunnableContext context = JavaPlugin.getActiveWorkbenchWindow();
      if (context == null) context = new BusyIndicatorRunnableContext();
      PlatformUI.getWorkbench()
          .getProgressService()
          .runInUI(
              context,
              new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()),
              operation.getSchedulingRule());
      final String[] created = operation.getCreatedMethods();
      if (created == null || created.length == 0)
        MessageDialog.openInformation(
            shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found);
    } catch (InvocationTargetException exception) {
      ExceptionHandler.handle(exception, shell, getDialogTitle(), null);
    } catch (InterruptedException exception) {
      // Do nothing. Operation has been canceled by user.
    } finally {
      if (target != null) target.endCompoundChange();
    }
    notifyResult(true);
  }
示例#23
0
  public static void navigateToVisual(
      IEditorPart currentEditor, Browser browser, VpvVisualModel visualModel, int x, int y) {
    String stringToEvaluate = ""; // $NON-NLS-1$
    if (OS.LINUX.equals(PlatformUtil.getOs())) {
      /* outerHTML is not available with XulRunner we shipping, so <code>result</code> variable will be null
       * because we make it default browser on Linux this workaround is used
       * @see JBIDE-17454
       */
      stringToEvaluate =
          "var selected = document.elementFromPoint("
              + x
              + ", "
              + y
              + ");"
              + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
              "var temp = document.createElement('div');"
              + //$NON-NLS-1$
              "temp.appendChild(selected.cloneNode(true));"
              + //$NON-NLS-1$
              "return temp.innerHTML;"; //$NON-NLS-1$
    } else {
      stringToEvaluate =
          "return document.elementFromPoint("
              + x
              + ", "
              + y
              + ").outerHTML;"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    String result = (String) browser.evaluate(stringToEvaluate);
    if (result != null) {
      String selectedElementId =
          TransformUtil.getSelectedElementId(result, "(?<=data-vpvid=\").*?(?=\")"); // $NON-NLS-1$

      Long id =
          (selectedElementId != null
                  && !selectedElementId.isEmpty()) // avoiding NumberFormatException
              ? Long.parseLong(selectedElementId)
              : null;
      NavigationUtil.outlineSelectedElement(browser, id);

      String fileExtension = EditorUtil.getFileExtensionFromEditor(currentEditor);

      if (SuitableFileExtensions.isHTML(fileExtension)) {
        try {
          Node visualNode = TransformUtil.getVisualNodeByVpvId(visualModel, selectedElementId);
          Node sourseNode = TransformUtil.getSourseNodeByVisualNode(visualModel, visualNode);

          if (sourseNode != null && sourseNode instanceof IDOMNode) {
            int startOffset = ((IDOMNode) sourseNode).getStartOffset();
            int endOffset = ((IDOMNode) sourseNode).getEndOffset();

            StructuredTextEditor editor =
                (StructuredTextEditor) currentEditor.getAdapter(StructuredTextEditor.class);
            editor.selectAndReveal(startOffset, endOffset - startOffset);
          }

        } catch (XPathExpressionException e) {
          Activator.logError(e);
        }
      }
    }
  }