示例#1
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();
          }
        };
  }