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.
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:
-
Create New Plug-in project (you need Eclipse RCP with CloverETL Designer)
[list:1feiu6ak][*:1feiu6ak] set Project name: customComponentGUI -
on the next wizard page set:
[list:1feiu6ak][*:1feiu6ak] ID: com.mycompany.gui -
Name: CustomComponentGUI
-
Provider: My Company
-
Activator: com.mycompany.gui.Activator
[/*1feiu6ak][/list:u:1feiu6ak][/*1feiu6ak] -
Set project Dependencies:
[*:1feiu6ak] org.eclipse.ui.views (remove version) -
com.cloveretl.gui (remove version)
[/*1feiu6ak] -
Define Extensions (your editors):
[*:1feiu6ak] com.cloveretl.gui.editor
[list:1feiu6ak][*:1feiu6ak] id: myEditor -
name: myEditor - this name is used in xml component definition:
<property category="basic" displayName="divident" modifiable="true" name="dividentField" nullable="true">
<singleType name="myEditor" />
</property>
-
class: com.mycompany.gui.editors.MyEditor
[/*1feiu6ak][/list:u:1feiu6ak][/*1feiu6ak] -
Create your editor
[*:1feiu6ak] create New Package: com.mycompany.gui.editors -
create New Class: MyEditor extends AbstractUIPropertyToolkit
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;
}
}
[/*1feiu6ak]
- Create New Feature Project
[list:1feiu6ak][*:1feiu6ak] Project name: customComponentFeature
[*:1feiu6ak] ID: com.mycompany.feature
[/*1feiu6ak]
-
Add com.mycompany.gui in Referenced Plug-ins and Fragments page
[/list:u:1feiu6ak][/*1feiu6ak] -
Create New Update Site Project
[*:1feiu6ak] Project name: customComponentUpdateSite
[/*1feiu6ak] -
Add Feature: com.mycompany.feature
-
Build update site
[/list:o:1feiu6ak]
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.
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.
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?
Hi,
Are you following http://help.eclipse.org/indigo/index.js … oject.html ? What version and edition of Eclipse/Designer did you download?