public MergeSourceViewer(
      SourceViewer sourceViewer, ResourceBundle bundle, ICompareContainer container) {
    Assert.isNotNull(sourceViewer);
    fSourceViewer = sourceViewer;
    fResourceBundle = bundle;
    fContainer = container;

    MenuManager menu = new MenuManager();
    menu.setRemoveAllWhenShown(true);
    menu.addMenuListener(this);
    StyledText te = getSourceViewer().getTextWidget();
    te.setMenu(menu.createContextMenu(te));
    fContainer.registerContextMenu(menu, getSourceViewer());

    // for listening to editor show/hide line number preference value
    fPreferenceChangeListener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            MergeSourceViewer.this.handlePropertyChangeEvent(event);
          }
        };
    EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener);
    fShowLineNumber =
        EditorsUI.getPreferenceStore()
            .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
    if (fShowLineNumber) {
      updateLineNumberRuler();
    }

    IOperationHistory history = getHistory();
    if (history != null) history.addOperationHistoryListener(this);

    // don't add save when in a dialog, IWorkbenchPart is null in dialog containers
    fAddSaveAction = fContainer.getWorkbenchPart() != null;
  }
Esempio n. 2
0
  /**
   * Internal hook method called when the input to this viewer is initially set or subsequently
   * changed.
   *
   * <p>The <code>ContentMergeViewer</code> implementation of this <code>Viewer</code> method tries
   * to save the old input by calling <code>doSave(...)</code> and then calls <code>
   * internalRefresh(...)</code> .
   *
   * @param input the new input of this viewer, or <code>null</code> if there is no new input
   * @param oldInput the old input element, or <code>null</code> if there was previously no input
   */
  protected final void inputChanged(Object input, Object oldInput) {

    if (input != oldInput && oldInput != null) {
      ICompareInputLabelProvider lp = getCompareConfiguration().getLabelProvider();
      if (lp != null) lp.removeListener(labelChangeListener);
    }

    if (input != oldInput && oldInput instanceof ICompareInput) {
      ICompareContainer container = getCompareConfiguration().getContainer();
      container.removeCompareInputChangeListener(
          (ICompareInput) oldInput, fCompareInputChangeListener);
    }

    boolean success = doSave(input, oldInput);

    if (input != oldInput && input instanceof ICompareInput) {
      ICompareContainer container = getCompareConfiguration().getContainer();
      container.addCompareInputChangeListener((ICompareInput) input, fCompareInputChangeListener);
    }

    if (input != oldInput && input != null) {
      ICompareInputLabelProvider lp = getCompareConfiguration().getLabelProvider();
      if (lp != null) lp.addListener(labelChangeListener);
    }

    if (success) {
      setLeftDirty(false);
      setRightDirty(false);
    }

    if (input != oldInput) internalRefresh(input);
  }
Esempio n. 3
0
  /**
   * Called on the viewer disposal. Unregisters from the compare configuration. Clients may extend
   * if they have to do additional cleanup.
   *
   * @see org.eclipse.jface.viewers.ContentViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
   */
  protected void handleDispose(DisposeEvent event) {

    if (fHandlerService != null) fHandlerService.dispose();

    Object input = getInput();
    if (input instanceof ICompareInput) {
      ICompareContainer container = getCompareConfiguration().getContainer();
      container.removeCompareInputChangeListener(
          (ICompareInput) input, fCompareInputChangeListener);
    }
    if (input != null) {
      ICompareInputLabelProvider lp = getCompareConfiguration().getLabelProvider();
      if (lp != null) lp.removeListener(labelChangeListener);
    }

    if (fPropertyChangeListener != null) {
      fCompareConfiguration.removePropertyChangeListener(fPropertyChangeListener);
      fPropertyChangeListener = null;
    }

    fAncestorLabel = null;
    fLeftLabel = null;
    fDirectionLabel = null;
    fRightLabel = null;
    fCenter = null;

    if (fRightArrow != null) {
      fRightArrow.dispose();
      fRightArrow = null;
    }
    if (fLeftArrow != null) {
      fLeftArrow.dispose();
      fLeftArrow = null;
    }
    if (fBothArrow != null) {
      fBothArrow.dispose();
      fBothArrow = null;
    }

    if (fNormalCursor != null) {
      fNormalCursor.dispose();
      fNormalCursor = null;
    }
    if (fHSashCursor != null) {
      fHSashCursor.dispose();
      fHSashCursor = null;
    }
    if (fVSashCursor != null) {
      fVSashCursor.dispose();
      fVSashCursor = null;
    }
    if (fHVSashCursor != null) {
      fHVSashCursor.dispose();
      fHVSashCursor = null;
    }

    super.handleDispose(event);
  }
 public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
   IServiceLocator serviceLocator = container.getServiceLocator();
   if (serviceLocator != null) {
     IHandlerService service = (IHandlerService) serviceLocator.getService(IHandlerService.class);
     if (service != null) return new CompareHandlerService(container, null);
   }
   if (container.getWorkbenchPart() == null && shell != null) {
     // We're in a dialog so we can use an active shell expression
     IHandlerService service =
         (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
     if (service != null) {
       Expression e = new ActiveShellExpression(shell);
       return new CompareHandlerService(container, e);
     }
   }
   return new CompareHandlerService(null, null);
 }
 private void initialize() {
   if (fHandlerService == null) {
     IServiceLocator serviceLocator = fContainer.getServiceLocator();
     if (serviceLocator != null) {
       IHandlerService service =
           (IHandlerService) serviceLocator.getService(IHandlerService.class);
       if (service != null) fHandlerService = service;
     }
     if (fHandlerService == null && fContainer.getWorkbenchPart() == null && fExpression != null) {
       // We're in a dialog so we can use an active shell expression
       IHandlerService service =
           (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
       if (service != null) {
         fHandlerService = service;
       }
     }
   }
 }
  private void addSave(IMenuManager menu) {
    ICommandService commandService =
        (ICommandService) fContainer.getWorkbenchPart().getSite().getService(ICommandService.class);
    final Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_SAVE);

    final IHandler handler = command.getHandler();
    if (handler != null) {
      if (fSaveContributionItem == null) {
        fSaveContributionItem =
            new CommandContributionItem(
                new CommandContributionItemParameter(
                    fContainer.getWorkbenchPart().getSite(),
                    null,
                    command.getId(),
                    CommandContributionItem.STYLE_PUSH));
      }
      // save is an editable dependent action, ie add only when edit
      // is possible
      if (handler.isHandled() && getSourceViewer().isEditable()) menu.add(fSaveContributionItem);
    }
  }
 private IActionBars getActionBars() {
   return fContainer.getActionBars();
 }