Beispiel #1
0
 void update() {
   if (parent != null) {
     if (parent.isDisposed()) return;
     parent.getShell().update();
   } else {
     display.update();
   }
 }
 public void createContents(Composite parent) {
   shell = parent.getShell();
   parent.setLayout(new FillLayout());
   folder = new TabFolder(shell, SWT.BORDER);
   labelTab();
   directoryDialogTab();
   buttonTab();
   sliderTab();
   scribbleTab();
   browserTab();
 }
  /**
   * Builds the SWT controls for the three areas of a compare/merge viewer.
   *
   * <p>Calls the hooks <code>createControls</code> and <code>createToolItems</code> to let
   * subclasses build the specific content areas and to add items to an enclosing toolbar.
   *
   * <p>This method must only be called in the constructor of subclasses.
   *
   * @param parent the parent control
   * @return the new control
   */
  protected final Control buildControl(Composite parent) {

    fComposite =
        new Composite(parent, fStyles | SWT.LEFT_TO_RIGHT) { // we
          // force
          // a
          // specific
          // direction
          public boolean setFocus() {
            return ContentMergeViewer.this.handleSetFocus();
          }
        };
    fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, getTitle());

    hookControl(fComposite); // hook help & dispose listener

    fComposite.setLayout(new ContentMergeViewerLayout());

    int style = SWT.SHADOW_OUT;
    fAncestorLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());

    fLeftLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());
    new Resizer(fLeftLabel, VERTICAL);

    fDirectionLabel = new CLabel(fComposite, style);
    fDirectionLabel.setAlignment(SWT.CENTER);
    new Resizer(fDirectionLabel, HORIZONTAL | VERTICAL);

    fRightLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());
    new Resizer(fRightLabel, VERTICAL);

    if (fCenter == null || fCenter.isDisposed()) fCenter = createCenterControl(fComposite);

    createControls(fComposite);

    fHandlerService =
        CompareHandlerService.createFor(
            getCompareConfiguration().getContainer(), fComposite.getShell());

    initializeToolbars(parent);

    return fComposite;
  }
  /**
   * This method is called from the <code>Viewer</code> method <code>inputChanged</code> to save any
   * unsaved changes of the old input.
   *
   * <p>The <code>ContentMergeViewer</code> implementation of this method calls <code>
   * saveContent(...)</code>. If confirmation has been turned on with <code>setConfirmSave(true)
   * </code>, a confirmation alert is posted before saving. Clients can override this method and are
   * free to decide whether they want to call the inherited method.
   *
   * @param newInput 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
   * @return <code>true</code> if saving was successful, or if the user didn't want to save (by
   *     pressing 'NO' in the confirmation dialog).
   * @since 2.0
   */
  protected boolean doSave(Object newInput, Object oldInput) {

    // before setting the new input we have to save the old
    if (isLeftDirty() || isRightDirty()) {

      if (Utilities.RUNNING_TESTS) {
        if (Utilities.TESTING_FLUSH_ON_COMPARE_INPUT_CHANGE) {
          flushContent(oldInput, null);
        }
      } else if (fConfirmSave) {
        // post alert
        Shell shell = fComposite.getShell();

        MessageDialog dialog =
            new MessageDialog(
                shell,
                Utilities.getString(getResourceBundle(), "saveDialog.title"), // $NON-NLS-1$
                null, // accept the default window icon
                Utilities.getString(getResourceBundle(), "saveDialog.message"), // $NON-NLS-1$
                MessageDialog.QUESTION,
                new String[] {
                  IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                },
                0); // default
        // button
        // index

        switch (dialog.open()) { // open returns index of pressed button
          case 0:
            flushContent(oldInput, null);
            break;
          case 1:
            setLeftDirty(false);
            setRightDirty(false);
            break;
          case 2:
            throw new ViewerSwitchingCancelled();
        }
      } else flushContent(oldInput, null);
      return true;
    }
    return false;
  }