示例#1
0
 public void run() {
   if (textViewer == null) {
     textViewer = notesViewer.getImplementation().getTextViewer();
   }
   if (textViewer != null) {
     if (textViewer.canDoOperation(op)) {
       textViewer.doOperation(op);
     }
   }
 }
示例#2
0
 /*
  * @see org.eclipse.jface.text.TextViewer#setHoverEnrichMode(org.eclipse.jface.text.ITextViewerExtension8.EnrichMode)
  * @since 3.4
  */
 public void setHoverEnrichMode(EnrichMode mode) {
   super.setHoverEnrichMode(mode);
   if (fVerticalRulerHoveringController != null)
     fVerticalRulerHoveringController.getInternalAccessor().setHoverEnrichMode(mode);
   if (fOverviewRulerHoveringController != null)
     fOverviewRulerHoveringController.getInternalAccessor().setHoverEnrichMode(mode);
 }
示例#3
0
  public void run() {

    TextViewer viewer = getTextViewer();
    if (viewer == null) return;

    IDocument document = viewer.getDocument();
    if (document == null) return;

    try {
      fLastLine = document.getLineOfOffset(document.getLength()) + 1;
    } catch (BadLocationException ex) {
      IStatus status =
          new Status(
              IStatus.ERROR,
              Q7UIPlugin.PLUGIN_ID,
              IStatus.OK,
              "Go to Line failed",
              ex); //$NON-NLS-1$
      Q7UIPlugin.getDefault().getLog().log(status);
      return;
    }

    String title = DIALOG_TITLE;
    String message = MessageFormat.format(DIALOG_MESSAGE, new Integer(fLastLine));

    String currentLineStr = ""; // $NON-NLS-1$
    StyledText textWidget = viewer.getTextWidget();
    int currentLine = textWidget.getLineAtOffset(textWidget.getCaretOffset());
    if (currentLine > -1) currentLineStr = Integer.toString(currentLine + 1);

    InputDialog d =
        new InputDialog(
            viewer.getTextWidget().getShell(),
            title,
            message,
            currentLineStr,
            new NumberValidator());
    if (d.open() == Window.OK) {
      try {
        int line = Integer.parseInt(d.getValue());
        gotoLine(line - 1);
      } catch (NumberFormatException x) {
      }
    }
  }
示例#4
0
  /*
   * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
   */
  public void setDocument(
      IDocument document,
      IAnnotationModel annotationModel,
      int modelRangeOffset,
      int modelRangeLength) {
    disposeVisualAnnotationModel();

    if (annotationModel != null && document != null) {
      fVisualAnnotationModel = createVisualAnnotationModel(annotationModel);
      fVisualAnnotationModel.connect(document);
    }

    if (modelRangeOffset == -1 && modelRangeLength == -1) super.setDocument(document);
    else super.setDocument(document, modelRangeOffset, modelRangeLength);

    if (fVerticalRuler != null) fVerticalRuler.setModel(fVisualAnnotationModel);

    if (fOverviewRuler != null) fOverviewRuler.setModel(fVisualAnnotationModel);
  }
示例#5
0
 @Override
 protected void handleDispose() {
   if (formatJob != null) {
     formatJob.cancel();
     formatJob = null;
   }
   Activator.getDefault().getPreferenceStore().removePropertyChangeListener(listener);
   if (refsChangedListener != null) refsChangedListener.remove();
   refsChangedListener = null;
   super.handleDispose();
 }
示例#6
0
  private void gotoLine(int line) {

    TextViewer viewer = getTextViewer();

    IDocument document = viewer.getDocument();

    try {
      int start = document.getLineOffset(line);

      StyledText widget = viewer.getTextWidget();
      widget.setRedraw(false);
      {
        viewer.revealRange(start, 0);
        viewer.setSelectedRange(start, 0);
        widget.setFocus();
      }
      widget.setRedraw(true);
    } catch (BadLocationException e) {
      // ignore
    }
  }
 /** @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) */
 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
   if (!(selection instanceof IStructuredSelection)) return;
   Object element = ((IStructuredSelection) selection).getFirstElement();
   long id = -1;
   String name = null;
   if (element instanceof BundleDescription) {
     id = ((BundleDescription) element).getBundleId();
     name = ((BundleDescription) element).getSymbolicName();
   }
   if (element instanceof BundleStats) {
     id = ((BundleStats) element).getId();
     name = ((BundleStats) element).getSymbolicName();
   }
   if (id == -1) return;
   PluginDependencyGraphNode node =
       (PluginDependencyGraphNode) getDependencyGraph().get(new Long(id));
   String text =
       node == null ? NLS.bind(Messages.depend_noInformation, name) : node.toDeepString();
   viewer.getDocument().set(text);
   viewer.refresh();
 }
  /** @see IWorkbenchPart#createPartControl */
  public void createPartControl(Composite parent) {
    viewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.READ_ONLY);
    viewer.setDocument(new Document());

    IActionBars bars = getViewSite().getActionBars();

    final GlobalAction clearOutputAction = new ClearTextAction(viewer.getDocument());
    clearOutputAction.registerAsGlobalAction(bars);

    final GlobalAction selectAllAction = new SelectAllAction(viewer);
    selectAllAction.registerAsGlobalAction(bars);

    // Delete action shortcuts are not captured by the workbench
    // so we need our key binding service to handle Delete keystrokes for us
    this.viewer
        .getControl()
        .addKeyListener(
            new KeyAdapter() {
              public void keyPressed(KeyEvent e) {
                if (e.character == SWT.DEL) clearOutputAction.run();
              }
            });

    GlobalAction copyAction = new CopyTextSelectionAction(viewer);
    copyAction.registerAsGlobalAction(bars);

    bars.getToolBarManager().add(clearOutputAction);

    bars.updateActionBars();

    // creates a context menu with actions and adds it to the viewer control
    MenuManager menuMgr = new MenuManager();
    menuMgr.add(copyAction);
    menuMgr.add(clearOutputAction);
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);

    getViewSite().getPage().addSelectionListener(this);
  }
示例#9
0
  /*
   * @see org.eclipse.jface.text.TextViewer#handleDispose()
   */
  protected void handleDispose() {
    unconfigure();

    disposeVisualAnnotationModel();

    fVerticalRuler = null;

    fOverviewRuler = null;

    // http://dev.eclipse.org/bugs/show_bug.cgi?id=15300
    fComposite = null;

    super.handleDispose();
  }
示例#10
0
  /*
   * @see TextViewer#createControl(Composite, int)
   */
  protected void createControl(Composite parent, int styles) {

    if (fVerticalRuler != null || fOverviewRuler != null) {
      styles = (styles & ~SWT.BORDER);
      fComposite = new Canvas(parent, SWT.NONE);
      fComposite.setLayout(createLayout());
      parent = fComposite;
    }

    super.createControl(parent, styles);

    if (fVerticalRuler != null) fVerticalRuler.createControl(fComposite, this);
    if (fOverviewRuler != null) fOverviewRuler.createControl(fComposite, this);
  }
示例#11
0
 public void update(TextViewer textViewer) {
   setEnabled(textViewer.canDoOperation(op));
 }
示例#12
0
  /*
   * @see ITextOperationTarget#doOperation(int)
   */
  public void doOperation(int operation) {

    if (getTextWidget() == null || (!redraws() && operation != FORMAT)) return;

    switch (operation) {
      case CONTENTASSIST_PROPOSALS:
        fContentAssistant.showPossibleCompletions();
        return;
      case CONTENTASSIST_CONTEXT_INFORMATION:
        fContentAssistant.showContextInformation();
        return;
      case QUICK_ASSIST:
        // FIXME: must find a way to post to the status line
        /* String msg= */ fQuickAssistAssistant.showPossibleQuickAssists();
        // setStatusLineErrorMessage(msg);
        return;
      case INFORMATION:
        fInformationPresenter.showInformation();
        return;
      case FORMAT:
        {
          final Point selection = rememberSelection();
          final IRewriteTarget target = getRewriteTarget();
          final IDocument document = getDocument();
          IFormattingContext context = null;
          DocumentRewriteSession rewriteSession = null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension = (IDocumentExtension4) document;
            DocumentRewriteSessionType type =
                (selection.y == 0 && document.getLength() > 1000) || selection.y > 1000
                    ? DocumentRewriteSessionType.SEQUENTIAL
                    : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession = extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents = document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension =
                    (IContentFormatterExtension) fContentFormatter;
                context = createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(
                      FormattingContextProperties.CONTEXT_REGION,
                      new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage = getModelCoverage();
                  r = coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r = new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension = (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null) context.dispose();
          }
          return;
        }
      default:
        super.doOperation(operation);
    }
  }
示例#13
0
 /*
  * @see TextViewer#activatePlugins()
  */
 public void activatePlugins() {
   ensureAnnotationHoverManagerInstalled();
   ensureOverviewHoverManagerInstalled();
   super.activatePlugins();
 }
示例#14
0
  @Override
  public void createPartControl(Composite parent) {
    // add controls
    try {
      CWMetaInput input = (CWMetaInput) getEditorInput();
      CWScript document = new CWScript(input.getRootElement());
      List<CWParameter> documentParameters = document.getParameterList();
      String documentScript = document.getScript();

      /*GridLayout layout = new GridLayout();
      layout.numColumns = 1;
      parent.setLayout(layout);*/
      parent.setLayout(new FillLayout(SWT.VERTICAL));

      SashForm sashForm = new SashForm(parent, SWT.VERTICAL);

      // setup table
      final TableViewer tableViewer =
          new TableViewer(
              sashForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

      // setup name column
      TableViewerColumn colName = new TableViewerColumn(tableViewer, SWT.NONE);
      colName.getColumn().setWidth(200);
      colName.getColumn().setText("Name");
      colName.setLabelProvider(
          new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
              return ((CWParameter) element).getName();
            }
          });

      // setup value column
      TableViewerColumn colValue = new TableViewerColumn(tableViewer, SWT.NONE);
      colValue.getColumn().setWidth(200);
      colValue.getColumn().setText("Type");
      colValue.setLabelProvider(
          new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
              return ((CWParameter) element).getType();
            }
          });

      final Table table = tableViewer.getTable();
      table.setHeaderVisible(true);
      table.setLinesVisible(true);

      tableViewer.setContentProvider(ArrayContentProvider.getInstance());
      tableViewer.setInput(documentParameters);

      /*GridData gridData = new GridData();
      gridData.verticalAlignment = GridData.FILL;
      gridData.horizontalSpan = 2;
      gridData.grabExcessHorizontalSpace = true;
      gridData.grabExcessVerticalSpace = true;
      gridData.horizontalAlignment = GridData.FILL;*/
      // tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      // setup script text area
      final TextViewer textViewer = new TextViewer(sashForm, SWT.MULTI | SWT.V_SCROLL);
      textViewer.setDocument(new Document(documentScript));

      /*gridData = new GridData();
      gridData.verticalAlignment = GridData.FILL;
      gridData.horizontalSpan = 2;
      gridData.grabExcessHorizontalSpace = true;
      gridData.grabExcessVerticalSpace = true;
      gridData.horizontalAlignment = GridData.FILL;*/
      // textViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      sashForm.setWeights(new int[] {1, 3});

    } catch (Exception ex) {
      System.out.println(ex);
    }
  }
示例#15
0
  @Override
  protected Composite createPageContainer(Composite parent) {
    this.editorParent = parent;
    Composite composite = super.createPageContainer(parent);

    EditorUtil.initializeScrollbars(getHeaderForm().getForm());

    // create left tool bar that replaces form heading label
    try {
      FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead();

      Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$
      field.setAccessible(true);

      TitleRegion titleRegion = (TitleRegion) field.get(heading);

      leftToolBarManager = new ToolBarManager(SWT.FLAT);
      leftToolBar = leftToolBarManager.createControl(titleRegion);
      leftToolBar.addControlListener(
          new ControlAdapter() {
            private boolean ignoreResizeEvents;

            @Override
            public void controlResized(ControlEvent e) {
              if (ignoreResizeEvents) {
                return;
              }
              ignoreResizeEvents = true;
              try {
                // the tool bar contents has changed, update state
                updateHeaderImage();
                updateHeaderLabel();
              } finally {
                ignoreResizeEvents = false;
              }
            }
          });

      // titleLabel = new Label(titleRegion, SWT.NONE);
      // need a viewer for copy support
      TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY);
      // Eclipse 3.3 needs a document, otherwise an NPE is thrown
      titleViewer.setDocument(new Document());

      titleLabel = titleViewer.getTextWidget();
      titleLabel.setForeground(heading.getForeground());
      titleLabel.setFont(heading.getFont());
      // XXX work-around problem that causes field to maintain selection when unfocused
      titleLabel.addFocusListener(
          new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
              titleLabel.setSelection(0);
            }
          });

      titleRegion.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              // do not create busyLabel to avoid recursion
              updateSizeAndLocations();
            }
          });

      IHandlerService handlerService =
          (IHandlerService) getSite().getService(IHandlerService.class);
      if (handlerService != null) {
        textSupport = new CommonTextSupport(handlerService);
        textSupport.install(titleViewer, false);
      }
    } catch (Exception e) {
      if (!toolBarFailureLogged) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to obtain busy label toolbar",
                e)); //$NON-NLS-1$
      }
      if (titleLabel != null) {
        titleLabel.dispose();
        titleLabel = null;
      }
      if (leftToolBar != null) {
        leftToolBar.dispose();
        leftToolBar = null;
      }
      if (leftToolBarManager != null) {
        leftToolBarManager.dispose();
        leftToolBarManager = null;
      }
    }

    updateHeader();

    return composite;
  }
 public void registerTextPresentationListener(ITextPresentationListener listener) {
   ISourceViewer viewer = getSourceViewer();
   if (viewer instanceof TextViewer) {
     ((TextViewer) viewer).addTextPresentationListener(listener);
   }
 }