Ejemplo n.º 1
0
  /*
   * (non-Javadoc) Method declared on IPropertySheetEntry.
   */
  public void applyEditorValue() {
    if (editor == null) {
      return;
    }

    // Check if editor has a valid value
    if (!editor.isValueValid()) {
      return;
    }

    // See if the value changed and if so update
    Object newValue = editor.getValue();
    // boolean changed = false;
    // if (values.length > 1) {
    // changed = true;
    // } else if (editValue == null) {
    // if (newValue != null) {
    // changed = true;
    // }
    // } else if (!editValue.equals(newValue)) {
    // changed = true;
    // }
    //
    // // Set the editor value
    // if (changed) {
    // setValue(newValue);
    // }
    setValue(newValue);
  }
Ejemplo n.º 2
0
  /**
   * This method is used to set the cell editors text
   *
   * @param toEdit String to be set in the cell editor
   */
  public void setEditText(String toEdit) {

    // Get the cell editor
    CellEditor cellEditor = getCellEditor();

    // IF the cell editor doesn't exist yet...
    if (cellEditor == null) {
      // Do nothing
      return;
    }

    // Get the Text Compartment Edit Part
    IXtextAwareEditPart textEP = (IXtextAwareEditPart) getEditPart();

    // Get the Text control
    StyledText textControl = (StyledText) cellEditor.getControl();

    // Set the Figures text
    textEP.setLabelText(toEdit);

    // See RATLC00522324
    if (cellEditor instanceof TextCellEditorEx) {
      ((TextCellEditorEx) cellEditor).setValueAndProcessEditOccured(toEdit);
    } else {
      cellEditor.setValue(toEdit);
    }

    // Set the controls text and position the caret at the end of the text
    textControl.setSelection(toEdit.length());
  }
Ejemplo n.º 3
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
  /**
   * The <code>TextPropertyDescriptor</code> implementation of this <code>IPropertyDescriptor</code>
   * method creates and returns a new <code>TextCellEditor</code>.
   *
   * <p>The editor is configured with the current validator if there is one.
   *
   * @param parent the parent
   * @return the cell editor
   */
  public CellEditor createPropertyEditor(Composite parent) {
    CellEditor editor =
        new TextCellEditor(parent) {
          @Override
          protected Object doGetValue() {
            String value = (String) super.doGetValue();
            if (value == null || value.equals("")) // $NON-NLS-1$
            return (Double) null;
            return new Double(value);
          }

          @Override
          protected void doSetValue(Object value) {
            if (value == null) super.doSetValue(""); // $NON-NLS-1$
            else {
              Assert.isTrue(text != null && (value instanceof Double));
              super.doSetValue(((Double) value).toString());
            }
          }
        };
    editor.setValidator(DoubleCellEditorValidator.instance());
    setValidator(DoubleCellEditorValidator.instance());
    HelpSystem.bindToHelp(this, editor.getControl());
    return editor;
  }
 public CellEditor createPropertyEditor(Composite parent) {
   CellEditor editor = new PathCellEditor(parent);
   if (getValidator() != null) {
     editor.setValidator(getValidator());
   }
   return editor;
 }
Ejemplo n.º 6
0
 public Control getControl(Composite par) {
   if (editor == null) editor = data.getEditor(par);
   Control control = editor.getControl();
   if (control == null) {
     editor = data.getEditor(par);
     return editor.getControl();
   }
   return control;
 }
Ejemplo n.º 7
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.views.properties.IPropertySheetEntry#getEditor(org.eclipse
   * .swt.widgets.Composite)
   */
  public CellEditor getEditor(Composite parent) {

    if (editor == null || editor.getControl().isDisposed()) {
      editor = descriptor.createPropertyEditor(parent);
      if (editor != null) {
        editor.addListener(cellEditorListener);
      }
    }
    // && !eq(editor.getValue(), editValue)
    if (editor != null) {
      editor.setValue(editValue);
    }
    return editor;
  }
Ejemplo n.º 8
0
  public CellEditor getEditor(Composite parent) {

    if (editor == null) {
      editor = descriptor.createPropertyEditor(parent);
      if (editor != null) {
        editor.addListener(cellEditorListener);
      }
    }
    if (editor != null) {
      editor.setValue(editValue);
      setErrorText(editor.getErrorMessage());
    }
    return editor;
  }
Ejemplo n.º 9
0
 @Override
 public Object getValue(Object element, String property) {
   if (element instanceof EObject) {
     if (cellEditor instanceof CustomCheckboxCellEditor) {
       return cellEditor.getValue();
     } else if (cellEditor instanceof CustomComboBoxCellEditor) {
       // for combobox cell editors, the returned value is a list of strings
       return cellEditor.getValue();
     } else {
       // all other types of cell editors accept the object/feature value
       EObject object = (EObject) element;
       return object.eGet(feature);
     }
   }
   return getText(element);
 }
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.CellEditor#activate(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)
   */
  @Override
  public void activate(ColumnViewerEditorActivationEvent activationEvent) {
    if (activationEvent.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
        || activationEvent.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC) {
      // 通过tab键激活或者程序调用激活需要显示control
      super.activate(activationEvent);

    } else {

      // 这里特殊处理
      // 当用户用鼠标点击时希望直接改变值而不显示控件
      // 1、如果这里不用ui的异步执行,因为fireApplyEditorValue()方法中会将cellEditor这个内部变量设置为null,导致
      // org.eclipse.jface.viewers.ColumnViewerEditor.activateCellEditor(ColumnViewerEditorActivationEvent)的207行出现空指针错误
      // 利用异步执行后,会在activateCellEditor方法后才执行,就不会出错
      // 2、其次因为有个异步问题,会出现combobox出现一瞬间后消失,会让用户感觉上不好,所以需要屏蔽这种现象
      // 采用的方法是先禁用父容器的重绘,就是父容器的显示将不变化,当全部操作以后才恢复父容器的重绘,其中的闪现问题将消失
      getControl().getParent().setRedraw(false);
      Display.getDefault()
          .asyncExec(
              new Runnable() {

                @Override
                public void run() {

                  bValue = !bValue;
                  fireApplyEditorValue();
                  getControl().getParent().setRedraw(true);
                }
              });
    }
  }
 public void deactivate() {
   if (activeEditor != null) {
     Control control = activeEditor.getControl();
     if (control != null && !control.isDisposed()) {
       control.setVisible(false);
     }
   }
 }
 @Override
 public void relocate(CellEditor celleditor) {
   Text text = (Text) celleditor.getControl();
   Point prefSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Rectangle rectangle = label.getTextBounds().getCopy();
   label.translateToAbsolute(rectangle);
   text.setBounds(rectangle.x - 1, rectangle.y - 1, prefSize.x + 1, prefSize.y + 1);
 }
Ejemplo n.º 13
0
 public void editorValueChanged(boolean oldValidState, boolean newValidState) {
   if (!newValidState)
     // currently not valid so show an error message
     setErrorText(editor.getErrorMessage());
   else
     // currently valid
     setErrorText(null);
 }
Ejemplo n.º 14
0
 /** Set the descriptor. */
 private void setDescriptor(
     IPropertyDescriptor newDescriptor) { // if our descriptor is changing, we have to get rid
   // of our current editor if there is one
   if (descriptor != newDescriptor && editor != null) {
     editor.dispose();
     editor = null;
   }
   descriptor = newDescriptor;
 } /*
Ejemplo n.º 15
0
 /** @generated */
 public void relocate(CellEditor celleditor) {
   Text text = (Text) celleditor.getControl();
   Rectangle rect = getLabel().getTextBounds().getCopy();
   getLabel().translateToAbsolute(rect);
   int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
   rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
   if (!rect.equals(new Rectangle(text.getBounds()))) {
     text.setBounds(rect.x, rect.y, rect.width, rect.height);
   }
 }
Ejemplo n.º 16
0
 /** @generated */
 public void relocate(CellEditor celleditor) {
   Text text = (Text) celleditor.getControl();
   Rectangle rect = getMultilineEditableFigure().getBounds().getCopy();
   rect.x = getMultilineEditableFigure().getEditionLocation().x;
   rect.y = getMultilineEditableFigure().getEditionLocation().y;
   getMultilineEditableFigure().translateToAbsolute(rect);
   if (getMultilineEditableFigure().getText().length() > 0) {
     rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
   }
   if (!rect.equals(new Rectangle(text.getBounds()))) {
     text.setBounds(rect.x, rect.y, rect.width, rect.height);
   }
 }
    protected void doSetValue(Object value) {

      if (((IStructuredSelection) this.viewer.getSelection()).getFirstElement()
          instanceof MyModel3) {
        activeEditor = delegatingCheckBoxEditor;
      } else if (((IStructuredSelection) this.viewer.getSelection()).getFirstElement()
          instanceof MyModel2) {
        activeEditor = delegatingDropDownEditor;
      } else {
        activeEditor = delegatingTextEditor;
      }

      activeEditor.setValue(value);
    }
Ejemplo n.º 18
0
 public void dispose() {
   if (editor != null) {
     editor.dispose();
     editor = null;
   } // recursive call to dispose children
   if (childEntries != null)
     for (int i = 0;
         i < childEntries.length;
         i++) { // an error in a property source may cause refreshChildEntries
       // to fail. Since the Workbench handles such errors we
       // can be left in a state where a child entry is null.
       if (childEntries[i] != null) childEntries[i].dispose();
     }
 }
Ejemplo n.º 19
0
  @Override
  protected Object getValue(Object element) {
    VolumeOption entryBeingAdded = getEntryBeingAdded();
    if (entryBeingAdded == null) {
      return cellEditor.getValue();
    }

    if (entryBeingAdded.getKey().isEmpty()) {
      // editing just about to start. set first element as default.
      return 0;
    }

    return getIndexOfEntry(entryBeingAdded);
  }
Ejemplo n.º 20
0
    protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
      int idx = ((Integer) cellEditor.getValue()).intValue();
      String[] items = ((ComboBoxCellEditor) cellEditor).getItems();

      String selectedVersion = items[idx];
      cell.setText(selectedVersion);

      if (cell.getElement() instanceof JarDiff) {
        ((JarDiff) cell.getElement()).setSelectedVersion(selectedVersion);
        return;
      }
      PackageInfo modelElement = (PackageInfo) cell.getElement();
      modelElement.setSelectedVersion(selectedVersion);
    }
Ejemplo n.º 21
0
    @Override
    protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
      int idx = ((Integer) cellEditor.getValue()).intValue();
      String[] items = ((ComboBoxCellEditor) cellEditor).getItems();

      String selectedVersion = items[idx];
      cell.setText(selectedVersion);

      if (cell.getElement() instanceof Baseline) {
        ((Baseline) cell.getElement()).setSuggestedVersion(Version.parseVersion(selectedVersion));
      } else if (cell.getElement() instanceof Info) {
        ((Info) cell.getElement()).suggestedVersion = Version.parseVersion(selectedVersion);
      }
    }
  public void relocate(CellEditor celleditor) {
    if (celleditor == null) return;
    Text text = (Text) celleditor.getControl();

    Rectangle rect = fig.getClientArea(Rectangle.SINGLETON);
    if (fig instanceof Label) rect = ((Label) fig).getTextBounds().intersect(rect);
    fig.translateToAbsolute(rect);

    org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
    rect.translate(trim.x, trim.y);
    rect.width += trim.width;
    rect.height += trim.height;

    text.setBounds(rect.x, rect.y, rect.width, rect.height);
  }
  @Override
  protected void setValue(Object element, Object value) {
    // Locals
    CCombo statesCombo = (CCombo) editor.getControl();

    if (element instanceof Release) {
      ((Release) element).setState(statesCombo.getText());
    } else if (element instanceof Iteration) {
      // TODO: ??
    } else if (element instanceof UserStory) {
      ((UserStory) element).setState(statesCombo.getText());
    } else if (element instanceof Task) {
      ((Task) element).setState(statesCombo.getText());
    }
    // Update viewer
    getViewer().update(element, null);
  }
Ejemplo n.º 24
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public void dispose() {
   if (editor != null) {
     editor.dispose();
     editor = null;
   }
   // recursive call to dispose children
   PropertySheetEntry[] entriesToDispose = childEntries;
   childEntries = null;
   if (entriesToDispose != null) {
     for (int i = 0; i < entriesToDispose.length; i++) {
       // an error in a property source may cause refreshChildEntries
       // to fail. Since the Workbench handles such errors we
       // can be left in a state where a child entry is null.
       if (entriesToDispose[i] != null) {
         entriesToDispose[i].dispose();
       }
     }
   }
 }
  @Override
  protected Object getValue(Object element) {
    // Locals
    CCombo statesCombo = (CCombo) editor.getControl();
    String state = null;

    if (element instanceof Release) {
      state = ((Release) element).getState();
    } else if (element instanceof Iteration) {
      // TODO: ??
    } else if (element instanceof UserStory) {
      state = ((UserStory) element).getState();
    } else if (element instanceof Task) {
      state = ((Task) element).getState();
    }
    // Set combo new state
    statesCombo.setText(state);

    return new Integer(-2);
  }
Ejemplo n.º 26
0
    protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {

      String selectedVersion;
      if (cell.getElement() instanceof JarDiff) {
        selectedVersion = ((JarDiff) cell.getElement()).getSelectedVersion();
      } else {
        PackageInfo pi = (PackageInfo) cell.getElement();
        selectedVersion = pi.getSelectedVersion();
      }

      String[] items = ((ComboBoxCellEditor) cellEditor).getItems();
      int idx = 0;
      for (int i = 0; i < items.length; i++) {
        if (items[i].equals(selectedVersion)) {
          idx = i;
          break;
        }
      }

      cellEditor.setValue(idx);
      cell.setText(selectedVersion);
    }
Ejemplo n.º 27
0
    @Override
    protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {

      String selectedVersion = "";
      if (cell.getElement() instanceof Baseline) {
        selectedVersion = ((Baseline) cell.getElement()).getSuggestedVersion().toString();
      } else if (cell.getElement() instanceof Info) {
        selectedVersion = ((Info) cell.getElement()).suggestedVersion.toString();
      }

      String[] items = ((ComboBoxCellEditor) cellEditor).getItems();
      int idx = 0;
      for (int i = 0; i < items.length; i++) {
        if (items[i].equals(selectedVersion)) {
          idx = i;
          break;
        }
      }

      cellEditor.setValue(idx);
      cell.setText(selectedVersion);
    }
 @Override
 protected IObservableValue doCreateCellEditorObservable(CellEditor editor) {
   return SWTObservables.observeText(editor.getControl());
 }
 @Override
 public CellEditor createPropertyEditor(Composite parent) {
   CellEditor editor = super.createPropertyEditor(parent);
   HelpSystem.bindToHelp(this, editor.getControl());
   return editor;
 }
 public void relocate(CellEditor celleditor) {
   Text text = (Text) celleditor.getControl();
   Point origin = getViewportOrigin().getNegated();
   Rectangle rect = label.getTextBounds().getCopy().expand(5, 0).translate(origin);
   text.setBounds(rect.x, rect.y, rect.width, rect.height);
 }