Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gmf-dev] [Fwd: editing EObject attributes]

Hi,

a Happy New Year to all of you!

Two weeks ago I posted the reasoning quoted below to the gmf newsgroup.

In the meantime I came up with a solution following the last option I mentioned (open a dialog to edit attributes).

I implemented a little framework analogous to the JFace FieldEditor classes (where I took a lot of code from). The idea
is to have an abstract AttributeEditor and concrete versions of it for the basic EMF attribute types. I also added a
multiline version for string attributes. Finally the framework provides an abstract AttributeEditorDialog which
assembles a Command if closed with ok. It defines an abstract method createAttributeEditors() in which the concrete
derived class calls a factory method createEditor() of the base class which among other parameters is passed an
EAttribute. The base class then determines the appropriate AttributeEditor and creates it.

In my example that looks like (see the attached screenshot):

public class ActionEmailDialog extends AttributeEditorDialog {

    private static final int WIDTH_IN_CHARS = 40;

    public ActionEmailDialog(Shell parentShell, EmailAction email) {
        super(parentShell, "Edit Email Fields", email);
    }

    @Override
    protected void createAttributeEditors() {

        StringAttributeEditor ed = (StringAttributeEditor) createEditor(
                RulesPackage.eINSTANCE.getEmailAction_From(), "From:", WIDTH_IN_CHARS);
        ed.setEmptyStringAllowed(false);

        ed = (StringAttributeEditor) createEditor(
                RulesPackage.eINSTANCE.getEmailAction_To(), "To:", WIDTH_IN_CHARS);
        ed.setEmptyStringAllowed(false);

        createEditor(
                RulesPackage.eINSTANCE.getEmailAction_Subject(), "Subject:", WIDTH_IN_CHARS);

        MultilineStringAttributeEditor med = (MultilineStringAttributeEditor) createEditor(
                RulesPackage.eINSTANCE.getEmailAction_Body(), "Body:", WIDTH_IN_CHARS, SWT.MULTI);
        med.setVSize(convertHeightInCharsToPixels(10));

        createEditor(
                RulesPackage.eINSTANCE.getEmailAction_Smtp(), "SMTP Server:", WIDTH_IN_CHARS);

        createEditor(
                RulesPackage.eINSTANCE.getEmailAction_User(), "SMTP User:", WIDTH_IN_CHARS);

        createEditor(
                RulesPackage.eINSTANCE.getEmailAction_Passwd(), "SMTP Password:", WIDTH_IN_CHARS);

        IntegerAttributeEditor ied = (IntegerAttributeEditor) createEditor(
                RulesPackage.eINSTANCE.getAction_Timeout(), "Timeout [sec]:", WIDTH_IN_CHARS);
        ied.setValidRange(0, 3600);

        createEditor(
                RulesPackage.eINSTANCE.getAction_BackgroundExecution(), "Background Execution", WIDTH_IN_CHARS);
    }
}

Using this dialog from the respective EditPart is very simple then:

public void performRequest(Request request) {
    if (request.getType().equals(RequestConstants.REQ_OPEN)) {
        Shell shell = getViewer().getControl().getShell();
        EmailAction email = (EmailAction)((View)getModel()).getElement();
        ActionEmailDialog dlg = new ActionEmailDialog(shell, email);
        if (dlg.open()==Window.OK) {
            CommandStack stack =
                getViewer().getEditDomain().getCommandStack();
            stack.execute(dlg.getCommand());
        }
    }
}


Of course there are many things that could be improved. Most prominently I want to mention the possibilties to layout
the dialog which are pretty limited in the JFace FieldEditor framework too because of its usage of a GridLayout where a
FormLayout would give more freedom. Also it would be nice to have a simple possibility to group editors in the dialog...

Nevertheless, after some more elaboration this might be a contribution to something like org.eclipse.gmf.emf.ui.dialogs.

What do you think?

Henrik


-------- Original Message --------
Subject: editing EObject attributes
Date: Fri, 23 Dec 2005 16:36:24 +0100
From: Henrik Rentz-Reichert <hrr@xxxxxxxxx>
Organization: EclipseCorner
Newsgroups: eclipse.technology.gmf

Hi,

I want to edit the EAttributes of an EObject which is represented as a graphical
node in the diagram.
However, the way this is done certainly is a question of style.

I see the following options:

- use compartments and let the user edit directly in the diagram
	should be used only for a couple of prominent attributes to avoid
	overloading the diagram
- use the Property View by adding a new category to the Advanced tab using
  standard EMF property descriptors (similar to the Notation styles of GMF)
	this is not very nice since items are ordered alphabetically rather than
	by meaning
- use a custom additional property view tab similar to the Appearance tab with
  its style editor and equip it with sort of a form for the desired fields
	this would be only useful if the (contents of the) tab could be switched
	depending on the current selection including the case that the whole tab
	is hidden if not appropriate
	Is this possible?
- use a dialog which e.g. is opened from the context menu of the current
  selection. This dialog could be implemented using a generic framework similar
  to the field editors of the preferences

Could anybody comment on that?

Thanks,
Henrik
	
-- 
..............................................			
 Henrik Rentz-Reichert  mailto://hrr@xxxxxxxxx

-- 
..............................................			
 Henrik Rentz-Reichert  mailto://hrr@xxxxxxxxx

JPEG image


Back to the top