Exemplo n.º 1
0
  private void initializeToolbars(Composite parent) {
    ToolBarManager tbm = CompareViewerPane.getToolBarManager(parent);
    if (tbm != null) {
      tbm.removeAll();

      // define groups
      tbm.add(new Separator("modes")); // $NON-NLS-1$
      tbm.add(new Separator("merge")); // $NON-NLS-1$
      tbm.add(new Separator("navigation")); // $NON-NLS-1$

      CompareConfiguration cc = getCompareConfiguration();

      if (cc.isRightEditable()) {
        fCopyLeftToRightAction =
            new Action() {
              public void run() {
                copy(true);
              }
            };
        Utilities.initAction(
            fCopyLeftToRightAction, getResourceBundle(), "action.CopyLeftToRight."); // $NON-NLS-1$
        tbm.appendToGroup("merge", fCopyLeftToRightAction); // $NON-NLS-1$
        fHandlerService.registerAction(
            fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight"); // $NON-NLS-1$
      }

      if (cc.isLeftEditable()) {
        fCopyRightToLeftAction =
            new Action() {
              public void run() {
                copy(false);
              }
            };
        Utilities.initAction(
            fCopyRightToLeftAction, getResourceBundle(), "action.CopyRightToLeft."); // $NON-NLS-1$
        tbm.appendToGroup("merge", fCopyRightToLeftAction); // $NON-NLS-1$
        fHandlerService.registerAction(
            fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft"); // $NON-NLS-1$
      }

      final ChangePropertyAction a =
          new ChangePropertyAction(
              fBundle,
              getCompareConfiguration(),
              "action.EnableAncestor.",
              ICompareUIConstants.PROP_ANCESTOR_VISIBLE); // $NON-NLS-1$
      a.setChecked(fAncestorVisible);
      fAncestorItem = new ActionContributionItem(a);
      fAncestorItem.setVisible(false);
      tbm.appendToGroup("modes", fAncestorItem); // $NON-NLS-1$
      tbm.getControl().addDisposeListener(a);

      createToolItems(tbm);
      updateToolItems();

      tbm.update(true);
    }
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
  /**
   * Creates a new content merge viewer and initializes with a resource bundle and a configuration.
   *
   * @param style SWT style bits
   * @param bundle the resource bundle
   * @param cc the configuration object
   */
  protected ContentMergeViewer(int style, ResourceBundle bundle, CompareConfiguration cc) {

    fStyles = style & ~(SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); // remove
    // BIDI
    // direction
    // bits
    fBundle = bundle;

    fAncestorVisible =
        Utilities.getBoolean(cc, ICompareUIConstants.PROP_ANCESTOR_VISIBLE, fAncestorVisible);
    fConfirmSave = Utilities.getBoolean(cc, CompareEditor.CONFIRM_SAVE_PROPERTY, fConfirmSave);

    setContentProvider(new MergeViewerContentProvider(cc));

    fCompareInputChangeListener =
        new ICompareInputChangeListener() {
          public void compareInputChanged(ICompareInput input) {
            if (input == getInput()) {
              handleCompareInputChange();
            }
          }
        };

    // Make sure the compare configuration is not null
    if (cc == null) fCompareConfiguration = new CompareConfiguration();
    else fCompareConfiguration = cc;
    fPropertyChangeListener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            ContentMergeViewer.this.handlePropertyChangeEvent(event);
          }
        };
    fCompareConfiguration.addPropertyChangeListener(fPropertyChangeListener);

    fLeftSaveAction = new SaveAction(true);
    fLeftSaveAction.setEnabled(false);
    fRightSaveAction = new SaveAction(false);
    fRightSaveAction.setEnabled(false);

    // this is used to update the dirty status,if we use
    // org.eclipse.php.internal.ui.compare.ContentMergeViewer,we will get a
    // ClassCastException
    cmv =
        new org.eclipse.compare.contentmergeviewer.ContentMergeViewer(
            fStyles, fBundle, fCompareConfiguration) {

          @Override
          protected void createControls(Composite composite) {}

          @Override
          protected void handleResizeAncestor(int x, int y, int width, int height) {}

          @Override
          protected void handleResizeLeftRight(
              int x, int y, int leftWidth, int centerWidth, int rightWidth, int height) {}

          @Override
          protected void updateContent(Object ancestor, Object left, Object right) {}

          @Override
          protected void copy(boolean leftToRight) {}

          @Override
          protected byte[] getContents(boolean left) {
            return null;
          }

          @Override
          public boolean internalIsLeftDirty() {
            return ContentMergeViewer.this.isLeftDirty();
          }

          @Override
          public boolean internalIsRightDirty() {
            return ContentMergeViewer.this.isRightDirty();
          }
        };
  }