/*
   * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
   * @since 3.0
   */
  @Override
  public void unconfigure() {
    if (fOutlinePresenter != null) {
      fOutlinePresenter.uninstall();
      fOutlinePresenter = null;
    }
    if (fStructurePresenter != null) {
      fStructurePresenter.uninstall();
      fStructurePresenter = null;
    }
    if (fHierarchyPresenter != null) {
      fHierarchyPresenter.uninstall();
      fHierarchyPresenter = null;
    }
    if (fForegroundColor != null) {
      fForegroundColor.dispose();
      fForegroundColor = null;
    }
    if (fBackgroundColor != null) {
      fBackgroundColor.dispose();
      fBackgroundColor = null;
    }

    if (fPreferenceStore != null) fPreferenceStore.removePropertyChangeListener(this);

    super.unconfigure();

    fIsConfigured = false;
  }
  /*
   * @see ITextOperationTarget#doOperation(int)
   */
  @Override
  public void doOperation(int operation) {
    if (getTextWidget() == null) return;

    switch (operation) {
      case SHOW_OUTLINE:
        if (fOutlinePresenter != null) fOutlinePresenter.showInformation();
        return;
      case OPEN_STRUCTURE:
        if (fStructurePresenter != null) fStructurePresenter.showInformation();
        return;
      case SHOW_HIERARCHY:
        if (fHierarchyPresenter != null) fHierarchyPresenter.showInformation();
        return;
    }

    super.doOperation(operation);
  }
示例#3
0
  /*
   * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
   * @since 3.0
   */
  public void unconfigure() {
    clearRememberedSelection();

    if (fPresentationReconciler != null) {
      fPresentationReconciler.uninstall();
      fPresentationReconciler = null;
    }

    if (fReconciler != null) {
      fReconciler.uninstall();
      fReconciler = null;
    }

    if (fContentAssistant != null) {
      fContentAssistant.uninstall();
      fContentAssistantInstalled = false;
      fContentAssistant = null;
      if (fContentAssistantFacade != null) fContentAssistantFacade = null;
    }

    if (fQuickAssistAssistant != null) {
      fQuickAssistAssistant.uninstall();
      fQuickAssistAssistantInstalled = false;
      fQuickAssistAssistant = null;
    }

    fContentFormatter = null;

    if (fInformationPresenter != null) {
      fInformationPresenter.uninstall();
      fInformationPresenter = null;
    }

    fAutoIndentStrategies = null;
    fDoubleClickStrategies = null;
    fTextHovers = null;
    fIndentChars = null;
    fDefaultPrefixChars = null;

    if (fVerticalRulerHoveringController != null) {
      fVerticalRulerHoveringController.dispose();
      fVerticalRulerHoveringController = null;
    }

    if (fOverviewRulerHoveringController != null) {
      fOverviewRulerHoveringController.dispose();
      fOverviewRulerHoveringController = null;
    }

    if (fUndoManager != null) {
      fUndoManager.disconnect();
      fUndoManager = null;
    }

    setHyperlinkDetectors(null, SWT.NONE);
  }
  /*
   * @see ISourceViewer#configure(SourceViewerConfiguration)
   */
  @Override
  public void configure(SourceViewerConfiguration configuration) {

    /*
     * Prevent access to colors disposed in unconfigure(), see:
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
     */
    StyledText textWidget = getTextWidget();
    if (textWidget != null && !textWidget.isDisposed()) {
      Color foregroundColor = textWidget.getForeground();
      if (foregroundColor != null && foregroundColor.isDisposed()) textWidget.setForeground(null);
      Color backgroundColor = textWidget.getBackground();
      if (backgroundColor != null && backgroundColor.isDisposed()) textWidget.setBackground(null);
    }

    super.configure(configuration);
    if (configuration instanceof JavaSourceViewerConfiguration) {
      JavaSourceViewerConfiguration javaSVCconfiguration =
          (JavaSourceViewerConfiguration) configuration;
      fOutlinePresenter = javaSVCconfiguration.getOutlinePresenter(this, false);
      if (fOutlinePresenter != null) fOutlinePresenter.install(this);

      fStructurePresenter = javaSVCconfiguration.getOutlinePresenter(this, true);
      if (fStructurePresenter != null) fStructurePresenter.install(this);

      fHierarchyPresenter = javaSVCconfiguration.getHierarchyPresenter(this, true);
      if (fHierarchyPresenter != null) fHierarchyPresenter.install(this);
    }

    if (fPreferenceStore != null) {
      fPreferenceStore.addPropertyChangeListener(this);
      initializeViewerColors();
    }

    fIsConfigured = true;
  }
示例#5
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);
    }
  }
示例#6
0
  /*
   * @see ISourceViewer#configure(SourceViewerConfiguration)
   */
  public void configure(SourceViewerConfiguration configuration) {

    if (getTextWidget() == null) return;

    setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));

    // install content type independent plug-ins
    fPresentationReconciler = configuration.getPresentationReconciler(this);
    if (fPresentationReconciler != null) fPresentationReconciler.install(this);

    fReconciler = configuration.getReconciler(this);
    if (fReconciler != null) fReconciler.install(this);

    fContentAssistant = configuration.getContentAssistant(this);
    if (fContentAssistant != null) {
      fContentAssistant.install(this);
      if (fContentAssistant instanceof IContentAssistantExtension4)
        fContentAssistantFacade = new ContentAssistantFacade(fContentAssistant);
      fContentAssistantInstalled = true;
    }

    fQuickAssistAssistant = configuration.getQuickAssistAssistant(this);
    if (fQuickAssistAssistant != null) {
      fQuickAssistAssistant.install(this);
      fQuickAssistAssistantInstalled = true;
    }

    fContentFormatter = configuration.getContentFormatter(this);

    fInformationPresenter = configuration.getInformationPresenter(this);
    if (fInformationPresenter != null) fInformationPresenter.install(this);

    setUndoManager(configuration.getUndoManager(this));

    getTextWidget().setTabs(configuration.getTabWidth(this));

    setAnnotationHover(configuration.getAnnotationHover(this));
    setOverviewRulerAnnotationHover(configuration.getOverviewRulerAnnotationHover(this));

    setHoverControlCreator(configuration.getInformationControlCreator(this));

    setHyperlinkPresenter(configuration.getHyperlinkPresenter(this));
    IHyperlinkDetector[] hyperlinkDetectors = configuration.getHyperlinkDetectors(this);
    int eventStateMask = configuration.getHyperlinkStateMask(this);
    setHyperlinkDetectors(hyperlinkDetectors, eventStateMask);

    // install content type specific plug-ins
    String[] types = configuration.getConfiguredContentTypes(this);
    for (int i = 0; i < types.length; i++) {

      String t = types[i];

      setAutoEditStrategies(configuration.getAutoEditStrategies(this, t), t);
      setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t);

      int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(this, t);
      if (stateMasks != null) {
        for (int j = 0; j < stateMasks.length; j++) {
          int stateMask = stateMasks[j];
          setTextHover(configuration.getTextHover(this, t, stateMask), t, stateMask);
        }
      } else {
        setTextHover(
            configuration.getTextHover(this, t), t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
      }

      String[] prefixes = configuration.getIndentPrefixes(this, t);
      if (prefixes != null && prefixes.length > 0) setIndentPrefixes(prefixes, t);

      prefixes = configuration.getDefaultPrefixes(this, t);
      if (prefixes != null && prefixes.length > 0) setDefaultPrefixes(prefixes, t);
    }

    activatePlugins();
  }