/**
  * Updates the contents of this cell editor, i.e. the value of gradientLabel with the given value.
  * Parameter value is a string if this method is called when user selects the editor. Parameter
  * value is GradientData if this method is called after user changed gradient (after opening
  * GradientSelectionDialog from this cell editor)
  *
  * @see org.eclipse.jface.viewers.DialogCellEditor#updateContents(java.lang.Object)
  */
 protected void updateContents(Object value) {
   if (value == null) {
     gradientLabel.setText(StringStatics.BLANK);
   } else if (value instanceof String) {
     gradientLabel.setText((String) value);
   } else {
     // format GradientData to string:
     //  RGB {x,x,x),RGB {x,x,x},style
     // (the same as in NotationPropertyDescriptor.getPropertyValue())
     GradientData gradient = (GradientData) value;
     StringBuffer sf = new StringBuffer();
     sf.append(FigureUtilities.integerToRGB(gradient.getGradientColor1()));
     sf.append(',');
     sf.append(FigureUtilities.integerToRGB(gradient.getGradientColor2()));
     sf.append(',');
     sf.append(GradientStyle.get(gradient.getGradientStyle()));
     gradientLabel.setText(sf.toString());
   }
 }
 /**
  * Opens GradientSelectionDialog without transparency setting available, receives the return
  * values and uses them to create the resulting GradientData object.
  *
  * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control)
  */
 protected Object openDialogBox(Control cellEditorWindow) {
   String value = (String) getValue();
   RGB color1 = null, color2 = null;
   int gradientStyle = -1;
   // value is in format: RGB {x, x, x},RGB {x, x, x},style
   // parse it
   if (value != null) {
     StringTokenizer st = new StringTokenizer(value, ",{}"); // $NON-NLS-1$
     try {
       int red, green, blue;
       st.nextToken().trim(); // RGB string			
       // color1
       red = Integer.parseInt(st.nextToken().trim());
       green = Integer.parseInt(st.nextToken().trim());
       blue = Integer.parseInt(st.nextToken().trim());
       if (red > -1 && green > -1 && blue > -1) {
         color1 = new RGB(red, green, blue);
       }
       st.nextToken().trim(); // RGB string			
       // color2
       red = Integer.parseInt(st.nextToken().trim());
       green = Integer.parseInt(st.nextToken().trim());
       blue = Integer.parseInt(st.nextToken().trim());
       if (red > -1 && green > -1 && blue > -1) {
         color2 = new RGB(red, green, blue);
       }
       // style
       GradientStyle gradientStyleObj =
           GradientStyle.get(value.substring(value.lastIndexOf(',') + 1).trim());
       if (gradientStyleObj != null) {
         gradientStyle = gradientStyleObj.getValue();
       }
     } finally {
       if (color1 == null || color2 == null || gradientStyle == -1) {
         value = null;
       }
     }
   }
   if (value == null) {
     // use default
     GradientData def = GradientData.getDefaultGradientData();
     color1 = FigureUtilities.integerToRGB(def.getGradientColor1());
     color2 = FigureUtilities.integerToRGB(def.getGradientColor2());
     gradientStyle = def.getGradientStyle();
   }
   GradientSelectionDialog dialog =
       new GradientSelectionDialog(
           cellEditorWindow.getShell(), SWT.APPLICATION_MODAL, color1, color2, gradientStyle, 0);
   int result = dialog.open();
   if (result == SWT.OK) {
     return new GradientData(
         FigureUtilities.RGBToInteger(dialog.getGradientColor1()),
         FigureUtilities.RGBToInteger(dialog.getGradientColor2()),
         dialog.getGradientStyle());
   } else if (result == -1) { // user selected Clear button
     // make the calls here, since parent ignores null, and we need to clear gradient
     markDirty();
     doSetValue(null);
     fireApplyEditorValue();
   }
   return null;
 }