Need good tutorial or example to create the custom editor

Discussion on developing CloverETL engine, transformation components etc.

ravipesala
Posts: 1
Joined: Mon Jan 03, 2011 12:10 pm

Need good tutorial or example to create the custom editor

Postby ravipesala » Mon Jan 03, 2011 12:26 pm

Hi,
I want to create custom plugin with editor for one of our complex requirements.I got an example from the jar file com.cloveretl.gui_3.0.1 but that is not working.That example says that extend your class with AbstractUIPropertyToolKit but that example is not working,I am not able to debug what was the problem.
There is no help document for creating custom editor,so please any one post the working example of custom plugin with editor. :)

avackova
Posts: 841
Joined: Fri Jul 20, 2007 9:28 am

Re: Need good tutorial or example to create the custom editor

Postby avackova » Tue Jan 04, 2011 3:04 pm

Hello Ravi Pesala,
the document is a bit musty, but we are working on the new one.
Here is a brief development plan for new editor:
  1. Create New Plug-in project (you need Eclipse RCP with CloverETL Designer)
    • set Project name: customComponentGUI
    • on the next wizard page set:
      • ID: com.mycompany.gui
      • Name: CustomComponentGUI
      • Provider: My Company
      • Activator: com.mycompany.gui.Activator
  2. Set project Dependencies:
    • org.eclipse.ui.views (remove version)
    • com.cloveretl.gui (remove version)
  3. Define Extensions (your editors):
    • com.cloveretl.gui.editor
      • id: myEditor
      • name: myEditor - this name is used in xml component definition:

        Code: Select all

               <property category="basic" displayName="divident" modifiable="true" name="dividentField" nullable="true">
                <singleType name="myEditor" />
              </property>

      • class: com.mycompany.gui.editors.MyEditor
  4. Create your editor
    • create New Package: com.mycompany.gui.editors
    • create New Class: MyEditor extends AbstractUIPropertyToolkit

      Code: Select all

      package com.mycompany.gui.editors;

      import org.eclipse.jface.dialogs.Dialog;
      import org.eclipse.jface.dialogs.IDialogConstants;
      import org.eclipse.jface.viewers.CellEditor;
      import org.eclipse.jface.viewers.DialogCellEditor;
      import org.eclipse.jface.viewers.ICellEditorValidator;
      import org.eclipse.jface.viewers.ILabelProvider;
      import org.eclipse.jface.window.Window;
      import org.eclipse.swt.SWT;
      import org.eclipse.swt.events.ModifyEvent;
      import org.eclipse.swt.events.ModifyListener;
      import org.eclipse.swt.layout.GridData;
      import org.eclipse.swt.widgets.Composite;
      import org.eclipse.swt.widgets.Control;
      import org.eclipse.swt.widgets.Shell;
      import org.eclipse.swt.widgets.Text;

      import com.cloveretl.gui.model.ElementBase;
      import com.cloveretl.gui.model.primitive.ExString;
      import com.cloveretl.gui.propertytoolkit.AbstractUIPropertyToolkit;
      import com.cloveretl.gui.propertytoolkit.PropertyLabelProvider;

      /**
       * Example implementation of simple multi-line editor for component's attribute in clover.GUI plugin.
       *
       * @author Martin Zatopek (martin.zatopek@javlinconsulting.cz)
       *         (c) Javlin Consulting (www.javlinconsulting.cz)
       *
       * @created 7.2.2007
       */
      public class MyEditor extends AbstractUIPropertyToolkit {
         
         /**
          * Validator used in dialog for user input validation.
          */
         private ICellEditorValidator validator;
         
          /**
           * This method should return cell editor for this property.
           * One of the most common used cell editor implementation is TextCellEditor.
           * In our example descendant DialogCellEditor is used, which provides cell editor
           * with extension button for custom dialog. 
           */
          public CellEditor getEditor(Composite parent) {
              return new MyCellEditor(parent, getValidator());
          }

          /**
           * This method returns implementation of ILabelProvider.
           * Using descendant of PropertyLabelProvider is highly recommended
           * for internal GUI features i.e. icons in required attributes.
           */
          public ILabelProvider getLabelProvider() {
              if(labelProvider == null) {
                  labelProvider = new PropertyLabelProvider((ElementBase) getEditableValue(), getPropertyDescriptor());
              }
             
              return labelProvider;
          }

          /**
           * This method can return validator for your property value.
           * This implementation checks if the value is a valid integer number.
           */
          public ICellEditorValidator getValidator() {
             if(validator == null) {
                validator = new ICellEditorValidator() {
                        public String isValid(Object value) {
                            if (value == null) return null;
                            String s = value.toString();
                            if (s.length() == 0) return null;
                            try {
                                Integer.parseInt(s);
                                return null;
                            } catch (NumberFormatException e) {
                                return "Not an integer number.";
                            }
                        }
                   };
             }
             return validator;
          }
      }

      /**
       * This cell editor is extened by button which opens multi-line dialog.
       *
       * @author Martin Zatopek (martin.zatopek@javlinconsulting.cz)
       *         (c) Javlin Consulting (www.javlinconsulting.cz)
       *
       * @created 7.2.2007
       */
      class MyCellEditor extends DialogCellEditor {

         private ICellEditorValidator validator;
         
         /**
          * Constructor.
          */
         public MyCellEditor(Composite parent, ICellEditorValidator validator) {
            super(parent);
            this.validator = validator;
         }

         /**
          * This is selection handler of dialog button in cell editor.
          * We only create and open multiline editor with appropriate validator and preseted value.
          */
         protected Object openDialogBox(Control cellEditorWindow) {
            ExString value = getValue() == null ? new ExString() : (ExString)getValue();
            MultiLineTextEditorDialog dialog = new MultiLineTextEditorDialog(getControl().getShell(), value, validator);
            dialog.create();
            return dialog.open() == Window.OK ? dialog.getValue() : dialog.getValue();
         }
      }

      /**
       * Simple dialog with one multi-line text editor and error message viewer.
       *
       * @author Martin Zatopek (martin.zatopek@javlinconsulting.cz)
       *         (c) Javlin Consulting (www.javlinconsulting.cz)
       *
       * @created 7.2.2007
       */
      class MultiLineTextEditorDialog extends Dialog {
         
         /**
          * The input value; the empty string by default.
          */
         private String value = "";//$NON-NLS-1$

         private ICellEditorValidator validator;
         
         /**
          * Input text widget.
          */
         private Text text;

         /**
          * Error message text widget.
          */
         private Text errorMessageText;

         /**
          * Constructor.
          */
         public MultiLineTextEditorDialog(Shell parentShell, ExString initialValue, ICellEditorValidator validator) {
            super(parentShell);
            this.validator = validator;
            setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);
            value = initialValue != null ? initialValue.getValue() : "";
         }
         
         /**
          * Before closing dialog we only store the result value for later usage.
          * @see #getValue()
          */
         protected void buttonPressed(int buttonId) {
            value = buttonId == IDialogConstants.OK_ID ? text.getText() : null;
            super.buttonPressed(buttonId);
         }
         
         /**
          * Here you can preset shell attributes like window title.
          */
         protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText("My multi-line editor");
         }

         /**
          * After all window widgets are ready to use, you can preset their values.
          */
         protected Control createContents(Composite parent) {
            Control control = super.createContents(parent);

            text.setFocus();
            if (value != null) {
               text.setText(value);
               text.selectAll();
            }

            return control;
         }
         
         /**
          * In this method you have to create all widgets in root composite of dialog.
          */
         protected Control createDialogArea(Composite parent) {
            // create root composite
            Composite composite = (Composite) super.createDialogArea(parent);
            // create main multi-line text editor
            text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
            text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH));
            text.addModifyListener(new ModifyListener() {
               public void modifyText(ModifyEvent e) {
                  validateInput();
               }
            });
            // create error message board
            errorMessageText = new Text(composite, SWT.READ_ONLY);
            errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
            errorMessageText.setBackground(errorMessageText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

            return composite;
         }

         private void validateInput() {
            setErrorMessage(validator.isValid(text.getText()));
         }

         public void setErrorMessage(String errorMessage) {
            errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$
            getButton(IDialogConstants.OK_ID).setEnabled(errorMessage == null);
            errorMessageText.getParent().update();
         }

         /**
          * Returns the string value typed into this dialog.
          */
         public String getValue() {
            return value;
         }
      }

  5. Create New Feature Project
      • Project name: customComponentFeature
      • ID: com.mycompany.feature
    • Add com.mycompany.gui in Referenced Plug-ins and Fragments page
  6. Create New Update Site Project
    • Project name: customComponentUpdateSite
  7. Add Feature: com.mycompany.feature
  8. Build update site

Now you can install your plug-in from just created update site.

If you created an engine plug-in with your component and imported your component in Preferences page, you should be able to use the editor for defined properties.
Agata Vackova
Javlin a.s.
agata.vackova@javlin.eu

wonderant
Posts: 2
Joined: Thu Dec 15, 2011 11:10 am

Re: Need good tutorial or example to create the custom editor

Postby wonderant » Thu Dec 15, 2011 11:15 am

This was a great article. I went through it in under ten minutes and everything worked first time. Which almost never happens with plug-in development in Eclipse. EVEN when you're just copy and pasting. :)

mazzin
Posts: 1
Joined: Mon Feb 10, 2014 7:06 am

Re: Need good tutorial or example to create the custom edito

Postby mazzin » Tue Feb 11, 2014 2:36 am

This is driving me nuts! I have installed everything you can think of! But still can not see 'Plug-in Project'. Would you help please?

kubosj
Posts: 372
Joined: Thu Jan 12, 2012 9:10 am

Re: Need good tutorial or example to create the custom edito

Postby kubosj » Tue Feb 11, 2014 8:50 am

Hi,

Are you following http://help.eclipse.org/indigo/index.js ... oject.html ? What version and edition of Eclipse/Designer did you download?
Jaroslav Kubos
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com