Package de.innovationgate.eclipse.editors.design.pages

Source Code of de.innovationgate.eclipse.editors.design.pages.SchemaConfigurationPage

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.editors.design.pages;

import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.java.dev.genesis.ui.swt.SWTBinder;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.dialogs.ResourceSelectionDialog;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.texteditor.AddMarkerAction;
import org.eclipse.ui.texteditor.StatusTextEditor;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.design.dialogs.AddContentTypeMetaDefinitionDialog;
import de.innovationgate.eclipse.editors.models.WGASchemaDefinitionContentProvider;
import de.innovationgate.eclipse.editors.models.WGASchemaDefinitionLabelProvider;
import de.innovationgate.eclipse.editors.models.WGAreaDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGContentItemDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGContentTypeDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGDescriptionMetaFieldDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGEditorsMetaFieldDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGEventScriptMetaFieldDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGLanguageDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGLayoutMetaFieldDefinitionModel;
import de.innovationgate.eclipse.editors.models.WGPositioningMetaFieldDefinitionModel;
import de.innovationgate.eclipse.utils.ui.BeanChangedListener;
import de.innovationgate.eclipse.utils.ui.DoubleValueCellEditor;
import de.innovationgate.eclipse.utils.ui.EditableTableControl;
import de.innovationgate.eclipse.utils.ui.GenesisBoundFormPage;
import de.innovationgate.eclipse.utils.ui.GenesisBoundObject;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.ui.WidgetFactory;
import de.innovationgate.eclipse.utils.ui.model.PrimitiveTypeBean;
import de.innovationgate.eclipse.utils.ui.model.PrimitiveTypeBeanListTableModel;
import de.innovationgate.eclipse.utils.ui.model.WGASchemaDefinitionModel;
import de.innovationgate.eclipse.utils.ui.model.WGASchemaDefinitionModelListener;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.webgate.api.WGContentType;
import de.innovationgate.webgate.api.schemadef.WGAreaDefinition;
import de.innovationgate.webgate.api.schemadef.WGContentItemDefinition;
import de.innovationgate.webgate.api.schemadef.WGContentTypeDefinition;
import de.innovationgate.webgate.api.schemadef.WGLanguageDefinition;
import de.innovationgate.webgate.api.schemadef.WGMetaFieldDefinition;
import de.innovationgate.webgate.api.schemadef.WGSchemaDocumentDefinition;
import de.innovationgate.wga.model.BeanListTableModelListener;
import de.innovationgate.wga.model.Model;
import de.innovationgate.wga.model.ValidationError;

public class SchemaConfigurationPage extends GenesisBoundFormPage implements ISelectionChangedListener {

    public static final String ID = "de.innovationgate.eclipse.wgadesigner.pages.SchemaConfigurationPage";

    public static final String PAGE_TITLE = "Design Schema";

    private WGASchemaDefinitionModel _model;

    private Section _detailSection;

    private TreeViewer _treeViewer;

    private Map<String,Composite> _subforms = new HashMap<String, Composite>();   
    private Map<String,GenesisBoundObject<?>> _subformModels = new HashMap<String, GenesisBoundObject<?>>();

    private PrimitiveTypeBeanListTableModel<String> _allowedPositionsModel;

    private Label _lblAllowedPositionsTable;

    private EditableTableControl<PrimitiveTypeBean<String>> _tblAllowedPositions;

    private EditableTableControl<PrimitiveTypeBean<String>> _tblEditors;

    private PrimitiveTypeBeanListTableModel<String> _editorsModel;

    private EditableTableControl<PrimitiveTypeBean<String>> _tblItemTextValues;

    private PrimitiveTypeBeanListTableModel<String> _itemTextValuesModel;

    private EditableTableControl<PrimitiveTypeBean<Boolean>> _tblItemBooleanValues;

    private PrimitiveTypeBeanListTableModel<Boolean> _itemBooleanValuesModel;

    private Section _initialValuesSection;

    private Composite _initialTextValuesSectionClient;

    private Composite _initialBooleanValuesSectionClient;

    private Button _chkItemList;

    private Composite _initialNumberValuesSectionClient;

    private PrimitiveTypeBeanListTableModel<Number> _itemNumberValuesModel;

    private EditableTableControl<PrimitiveTypeBean<Number>> _tblItemNumberValues;

    private Label _lblInitialValues;

    private static final String SUBFORM_CONTENT_TYPE_DEFINITION = "SubformContentTypeDefinition";
    private static final String SUBFORM_AREA_DEFINITION = "SubformAreaDefinition";
    private static final String SUBFORM_LANGUAGE_DEFINITION = "SubformLanguageDefinition";
    private static final String SUBFORM_CONTENT_ITEM_DEFINITION = "SubformContentItemDefinition";
    private static final String SUBFORM_META_EVENTSCRIPT = "SubformMetaEventScript";
    private static final String SUBFORM_META_LAYOUT = "SubformMetaLayout";
    private static final String SUBFORM_META_POSITIONING = "SubformMetaPositioning";
    private static final String SUBFORM_META_EDITORS = "SubformMetaEditors";
    private static final String SUBFORM_META_DESCRIPTION = "SubformMetaDescription";
   
   
    public SchemaConfigurationPage(FormEditor editor) {
        super(editor, ID, PAGE_TITLE);
    }

    @Override
    public Model getModel() {
        return _model;
    }

    @Override
    public void setModel(Model model) {
        if (!(model instanceof WGASchemaDefinitionModel)) {
            throw new IllegalArgumentException("Unsupported model type '" + model.getClass().getName() + "'.");
        }
        _model = (WGASchemaDefinitionModel) model;
    }

    @Override
    protected void createFormContent(IManagedForm managedForm) {
        ScrolledForm form = managedForm.getForm();
        FormToolkit toolkit = managedForm.getToolkit();
        WidgetFactory factory = new WidgetFactory(toolkit);
       
        toolkit.decorateFormHeading(form.getForm());
        form.setText(PAGE_TITLE);

        GridLayout formLayout = new GridLayout(2, true);
        form.getBody().setLayout(formLayout);       
       
        // tree
        Section schemaSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        schemaSection.setText("Schema Definition");
        schemaSection.setLayoutData(new GridData(GridData.FILL_BOTH));
        // register schemaSection as error catcher
        registerField(WGASchemaDefinitionModel.PROPERTY_HINT_SCHEMADEF, schemaSection);
       
        Tree tree = toolkit.createTree(schemaSection, SWT.NONE);
        tree.setLayoutData(new GridData(GridData.FILL_BOTH));
        schemaSection.setClient(tree);
       
        final Menu menu = new Menu(Display.getCurrent().getActiveShell(), SWT.POP_UP);
        MenuItem itemNewContentTypeDefinition = new MenuItem(menu, SWT.PUSH);
        itemNewContentTypeDefinition.setText("Content Type Definition");
        itemNewContentTypeDefinition.addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                WGContentTypeDefinition cType = _model.createContentTypeDefinition();
                _treeViewer.expandToLevel(cType, 1);
                _treeViewer.setSelection(new SingleStructuredSelection(cType));               
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        MenuItem itemNewAreaDefinition = new MenuItem(menu, SWT.PUSH);
        itemNewAreaDefinition.setText("Area Definition");
        itemNewAreaDefinition.addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                WGAreaDefinition area = _model.createAreaDefinition();
                _treeViewer.expandToLevel(area, 1);
                _treeViewer.setSelection(new SingleStructuredSelection(area));               
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        MenuItem itemNewLanguageDefinition = new MenuItem(menu, SWT.PUSH);
        itemNewLanguageDefinition.setText("Language Definition");
        itemNewLanguageDefinition.addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                WGLanguageDefinition lang = _model.createLanguageDefinition();
                _treeViewer.expandToLevel(lang, 1);
                _treeViewer.setSelection(new SingleStructuredSelection(lang));               
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
       
       
        final ToolBar schemaSectionToolBar = new ToolBar(schemaSection, SWT.FLAT);
        final ToolItem schemaSectionItemNew = new ToolItem(schemaSectionToolBar, SWT.DROP_DOWN);
        schemaSectionItemNew.setText("new");
        schemaSectionItemNew.setImage(Plugin.getDefault().getImageRegistry().get(Plugin.IMAGE_SCHEMADEFINITION_ADD));
        schemaSectionItemNew.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {

                  Rectangle rect = schemaSectionItemNew.getBounds();
                  Point pt = new Point(rect.x, rect.y + rect.height);
                  pt = schemaSectionToolBar.toDisplay(pt);
                  menu.setLocation(pt.x, pt.y);
                  menu.setVisible(true);

              }
           }
        );
        final ToolItem schemaSectionItemDelete = new ToolItem(schemaSectionToolBar, SWT.PUSH);
        schemaSectionItemDelete.setText("delete");
        schemaSectionItemDelete.setImage(Plugin.getDefault().getImageRegistry().get(Plugin.IMAGE_SCHEMADEFINITION_REMOVE));
        schemaSectionItemDelete.addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = _treeViewer.getSelection();
                if (selection instanceof TreeSelection) {
                    TreeSelection treeSelection = (TreeSelection) selection;
                    Object node = treeSelection.getFirstElement();
                    if (node instanceof WGSchemaDocumentDefinition) {
                        WGSchemaDocumentDefinition def = (WGSchemaDocumentDefinition)node;
                        String typeName = "Document Definition";
                        if (def instanceof WGContentTypeDefinition) {
                            typeName = "Content Type Definition";
                        } else if (def instanceof WGAreaDefinition) {
                            typeName = "Area Definition";
                        } else if (def instanceof WGLanguageDefinition) {
                            typeName = "Language Definition";
                        }
                        boolean result = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Delete " + typeName, "Delete " + typeName + " '" + def.getName() + "'?");
                        if (result) {
                            _model.removeSchemaDocumentDefintion(def);
                        }
                    } else if (node instanceof WGContentItemDefinition) {
                        WGContentItemDefinition def = (WGContentItemDefinition)node;
                        String typeName = "Item Definition";
                        boolean result = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Delete " + typeName, "Delete " + typeName + " '" + def.getName() + "'?");
                        if (result) {
                            _model.remove(def);
                        }
                    } else if (node instanceof WGMetaFieldDefinition) {
                        WGMetaFieldDefinition def = (WGMetaFieldDefinition)node;
                        String typeName = "Property";
                        boolean result = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Delete " + typeName, "Delete " + typeName + " '" + AddContentTypeMetaDefinitionDialog.METADATA_DEFINITION_LABELS.get(def.getName()) + "'?");
                        if (result) {
                            _model.remove(def);
                        }
                    }
                }
               
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {
                // TODO Auto-generated method stub
               
            }
        });
       
        schemaSection.setTextClient(schemaSectionToolBar);
       
       
       
        _treeViewer = new TreeViewer(tree);
        _treeViewer.setContentProvider(new WGASchemaDefinitionContentProvider());              
        _treeViewer.setLabelProvider(new WGASchemaDefinitionLabelProvider());       
        _treeViewer.setComparator(new ViewerComparator() {

            @Override
            public int compare(Viewer viewer, Object e1, Object e2) {
                if (e1 != null && e2 != null) {
                    if (e1 instanceof WGMetaFieldDefinition && e2 instanceof WGMetaFieldDefinition) {
                        WGMetaFieldDefinition def1 = (WGMetaFieldDefinition) e1;
                        WGMetaFieldDefinition def2 = (WGMetaFieldDefinition) e2;
                        return AddContentTypeMetaDefinitionDialog.METADATA_DEFINITION_LABELS.get(def1.getName()).compareTo(AddContentTypeMetaDefinitionDialog.METADATA_DEFINITION_LABELS.get(def2.getName()));
                    } else if (e1 instanceof String && e2 instanceof String) {
                        if (e1.equals(WGASchemaDefinitionContentProvider.CONTENTTYPE_DEFINITIONS_ROOT)) {
                            return -1;
                        } else if (e1.equals(WGASchemaDefinitionContentProvider.AREA_DEFINITIONS_ROOT) && e2.equals(WGASchemaDefinitionContentProvider.LANGUAGE_DEFINITIONS_ROOT)) {
                            return -1;
                        } else {
                            return 1;
                        }                                                
                    } else if (e1 instanceof WGMetaFieldDefinition && e2 instanceof WGContentItemDefinition) {
                        return -1;
                    } else if (e1 instanceof WGContentItemDefinition && e2 instanceof WGMetaFieldDefinition) {
                        return 1;
                    } else if (e1 instanceof WGContentItemDefinition && e2 instanceof WGContentItemDefinition) {
                        WGContentItemDefinition def1 = (WGContentItemDefinition) e1;
                        WGContentItemDefinition def2 = (WGContentItemDefinition) e2;
                        if (def1.getName().startsWith("<") && !def2.getName().startsWith("<")) {
                            return 1;
                        } else if (def2.getName().startsWith("<") && !def1.getName().startsWith("<")) {
                            return -1;
                        } else {
                            return def1.getName().compareTo(def2.getName());
                        }
                    } else if (e1 instanceof WGContentTypeDefinition && e2 instanceof WGContentTypeDefinition) {
                        WGContentTypeDefinition def1 = (WGContentTypeDefinition) e1;
                        WGContentTypeDefinition def2 = (WGContentTypeDefinition) e2;
                        if (def1.getName().startsWith("<") && !def2.getName().startsWith("<")) {
                            return 1;
                        } else if (def2.getName().startsWith("<") && !def1.getName().startsWith("<")) {
                            return -1;
                        } else {
                            return def1.getName().compareTo(def2.getName());
                        }
                    } else if (e1 instanceof WGAreaDefinition && e2 instanceof WGAreaDefinition) {
                        WGAreaDefinition def1 = (WGAreaDefinition) e1;
                        WGAreaDefinition def2 = (WGAreaDefinition) e2;
                        if (def1.getName().startsWith("<") && !def2.getName().startsWith("<")) {
                            return 1;
                        } else if (def2.getName().startsWith("<") && !def1.getName().startsWith("<")) {
                            return -1;
                        } else {
                            return def1.getName().compareTo(def2.getName());
                        }
                    }  else if (e1 instanceof WGLanguageDefinition && e2 instanceof WGLanguageDefinition) {
                        WGLanguageDefinition def1 = (WGLanguageDefinition) e1;
                        WGLanguageDefinition def2 = (WGLanguageDefinition) e2;
                        if (def1.getName().startsWith("<") && !def2.getName().startsWith("<")) {
                            return 1;
                        } else if (def2.getName().startsWith("<") && !def1.getName().startsWith("<")) {
                            return -1;
                        } else {
                            return def1.getName().compareTo(def2.getName());
                        }
                    }
                   
                }
                return super.compare(viewer, e1, e2);
            }
           
        });
        _treeViewer.setInput(_model);      
        _treeViewer.addSelectionChangedListener(this);
                      
        // details
        _detailSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        _detailSection.setText("Details");
        _detailSection.setLayoutData(new GridData(GridData.FILL_BOTH));     

        // content type subform
        Composite subform = toolkit.createComposite(_detailSection);          
        GridLayout subformLayout = new GridLayout();       
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);              
        Text txtName = factory.createText(subform, "Name:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        factory.createCheckBox(subform, "Auto creation:", "Enabled", "autoCreate");

        Label lblActions = new Label(subform, SWT.NONE);
        lblActions.setText("Actions:");
        HyperlinkGroup actionGroup = new HyperlinkGroup(Display.getCurrent());
        Hyperlink defineMetas = new Hyperlink(subform, SWT.NONE);
        defineMetas.setText("add properties...");
        defineMetas.addHyperlinkListener(new IHyperlinkListener() {           
            public void linkExited(HyperlinkEvent e) {
            }
           
            public void linkEntered(HyperlinkEvent e) {              
            }
           
            public void linkActivated(HyperlinkEvent e) {
                handleAddMetaDataDefinition();               
            }
        });
        actionGroup.add(defineMetas);
       
        Label lbl = new Label(subform, SWT.NONE);
        Hyperlink defineItems = new Hyperlink(subform, SWT.NONE);
        defineItems.setText("add item definition...");
        defineItems.addHyperlinkListener(new IHyperlinkListener() {
           
            public void linkExited(HyperlinkEvent e) {
            }
           
            public void linkEntered(HyperlinkEvent e) {
            }
           
            public void linkActivated(HyperlinkEvent e) {
                handleAddItemDefinition();               
            }
        });
        actionGroup.add(defineItems);
       
        WGContentTypeDefinitionModel contentTypeDefinitionModel = new WGContentTypeDefinitionModel();
        contentTypeDefinitionModel.addListener(new BeanChangedListener<WGContentTypeDefinition>() {
            public void changed(WGContentTypeDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });               
        _subforms.put(SUBFORM_CONTENT_TYPE_DEFINITION, subform);
        _subformModels.put(SUBFORM_CONTENT_TYPE_DEFINITION, contentTypeDefinitionModel);
       
        // area subform
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);             
        txtName = factory.createText(subform, "Name:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        factory.createCheckBox(subform, "Auto creation:", "Enabled", "autoCreate");

        WGAreaDefinitionModel areaDefintionModel = new WGAreaDefinitionModel();
        areaDefintionModel.addListener(new BeanChangedListener<WGAreaDefinition>() {
            public void changed(WGAreaDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }           
        });
        _subforms.put(SUBFORM_AREA_DEFINITION, subform);
        _subformModels.put(SUBFORM_AREA_DEFINITION, areaDefintionModel);
       
        // language subform
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);             
        txtName = factory.createText(subform, "Name:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        factory.createCheckBox(subform, "Auto creation:", "Enabled", "autoCreate");
       
        WGLanguageDefinitionModel languageDefinitionModel = new WGLanguageDefinitionModel();
        languageDefinitionModel.addListener(new BeanChangedListener<WGLanguageDefinition>() {
            public void changed(WGLanguageDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }           
        });
        _subforms.put(SUBFORM_LANGUAGE_DEFINITION, subform);
        _subformModels.put(SUBFORM_LANGUAGE_DEFINITION, languageDefinitionModel);

        // item subform
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);
       
        Group parentGroup = createParentInformationGroup(subform);
        GridData parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 2;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Itemname:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        Combo itemTypeCombo = factory.createCombo(subform, "Type:", "type");       
        _chkItemList = factory.createCheckBox(subform, "List:", "Enabled", "list");

        _lblInitialValues = new Label(subform, SWT.NONE);
        _lblInitialValues.setText("Initial values:");
        _lblInitialValues.setLayoutData(new GridData(SWT.NONE, SWT.BEGINNING, false, false));
       
        _initialValuesSection = toolkit.createSection(subform, Section.EXPANDED | Section.NO_TITLE);
       
        GridData initialValuesSectionLayoutData = new GridData(GridData.FILL_BOTH);
        _initialValuesSection.setLayoutData(initialValuesSectionLayoutData);

        // item subform - text values
        _initialTextValuesSectionClient = toolkit.createComposite(_initialValuesSection);
        _initialTextValuesSectionClient.setLayout(new FillLayout());
        _tblItemTextValues = new EditableTableControl<PrimitiveTypeBean<String>>(_initialTextValuesSectionClient, SWT.NONE);
        _itemTextValuesModel = new PrimitiveTypeBeanListTableModel<String>(true);
        _itemTextValuesModel.addListener(new BeanListTableModelListener() {
           
            public void update(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void remove(Object bean) {
                _model.fireModelChanged();
            }
           
            public void refresh(List beans) {
            }
           
            public void add(Object bean) {
                _model.fireModelChanged();               
            }
        });
        _tblItemTextValues.init(new String[] {"#", "Value"}, _itemTextValuesModel);
        CellEditor[] cellEditors = new CellEditor[2];
        cellEditors[0] = null;
        cellEditors[1] = new TextCellEditor(_tblItemTextValues.getTable());
        _tblItemTextValues.getTableViewer().setCellEditors(cellEditors);
       
        _tblItemTextValues.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                WGContentItemDefinitionModel model = (WGContentItemDefinitionModel)_subformModels.get(SUBFORM_CONTENT_ITEM_DEFINITION);
                if (_itemTextValuesModel.getBeans().size() > 0) {                   
                    _chkItemList.setSelection(true);
                    model.setList(true);
                }
                handleAdd(_tblItemTextValues, "");
            }
        });

        _tblItemTextValues.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleRemove(_tblItemTextValues);
            }
        });
       
       
        // item subform - boolean values
        _initialBooleanValuesSectionClient = toolkit.createComposite(_initialValuesSection);
        _initialBooleanValuesSectionClient.setLayout(new FillLayout());
        _tblItemBooleanValues = new EditableTableControl<PrimitiveTypeBean<Boolean>>(_initialBooleanValuesSectionClient, SWT.NONE);
        _itemBooleanValuesModel = new PrimitiveTypeBeanListTableModel<Boolean>(true);
        _itemBooleanValuesModel.addListener(new BeanListTableModelListener() {
           
            public void update(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void remove(Object bean) {
                _model.fireModelChanged();
            }
           
            public void refresh(List beans) {
            }
           
            public void add(Object bean) {
                _model.fireModelChanged();               
            }
        });
        _tblItemBooleanValues.init(new String[] {"#", "Value"}, _itemBooleanValuesModel);
        cellEditors = new CellEditor[2];
        cellEditors[0] = null;
        cellEditors[1] = new CheckboxCellEditor(_tblItemBooleanValues.getTable());
        _tblItemBooleanValues.getTableViewer().setCellEditors(cellEditors);       
       
        _tblItemBooleanValues.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                WGContentItemDefinitionModel model = (WGContentItemDefinitionModel)_subformModels.get(SUBFORM_CONTENT_ITEM_DEFINITION);
                if (_itemBooleanValuesModel.getBeans().size() > 0) {                   
                    _chkItemList.setSelection(true);
                    model.setList(true);
                }
                handleAdd(_tblItemBooleanValues, false);               
            }
        });

        _tblItemBooleanValues.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleRemove(_tblItemBooleanValues);
            }
        });
       
       
        // item subform - number values
        _initialNumberValuesSectionClient = toolkit.createComposite(_initialValuesSection);
        _initialNumberValuesSectionClient.setLayout(new FillLayout());
        _tblItemNumberValues = new EditableTableControl<PrimitiveTypeBean<Number>>(_initialNumberValuesSectionClient, SWT.NONE);        
        _itemNumberValuesModel = new PrimitiveTypeBeanListTableModel<Number>(true);
        _itemNumberValuesModel.addListener(new BeanListTableModelListener() {
           
            public void update(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void remove(Object bean) {
                _model.fireModelChanged();
            }
           
            public void refresh(List beans) {
            }
           
            public void add(Object bean) {
                _model.fireModelChanged();               
            }
        });
        _tblItemNumberValues.init(new String[] {"#", "Value"}, _itemNumberValuesModel);
        cellEditors = new CellEditor[2];
        cellEditors[0] = null;
        cellEditors[1] = new DoubleValueCellEditor(_tblItemNumberValues.getTable());

        _tblItemNumberValues.getTableViewer().setCellEditors(cellEditors);
       
        _tblItemNumberValues.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                WGContentItemDefinitionModel model = (WGContentItemDefinitionModel)_subformModels.get(SUBFORM_CONTENT_ITEM_DEFINITION);
                if (_itemNumberValuesModel.getBeans().size() > 0) {                   
                    _chkItemList.setSelection(true);
                    model.setList(true);
                }
                handleAdd(_tblItemNumberValues, 0);               
            }
        });

        _tblItemNumberValues.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleRemove(_tblItemNumberValues);
            }
        });
       
       
       
        itemTypeCombo.addModifyListener(new ModifyListener() {
           
            public void modifyText(ModifyEvent e) {
                WGContentItemDefinitionModel model = (WGContentItemDefinitionModel)_subformModels.get(SUBFORM_CONTENT_ITEM_DEFINITION);
                WGContentItemDefinition.Type type = model.getType().getKey();
                if (type.equals(WGContentItemDefinition.Type.TEXT)) {
                    _initialValuesSection.setVisible(true);
                    _lblInitialValues.setVisible(true);
                    _itemTextValuesModel.bind(model.getInitialValues());
                    _initialTextValuesSectionClient.setVisible(true);
                    _initialBooleanValuesSectionClient.setVisible(false);
                    _initialNumberValuesSectionClient.setVisible(false);
                    _initialValuesSection.setClient(_initialTextValuesSectionClient);
                    _initialValuesSection.layout();
                } else if (type.equals(WGContentItemDefinition.Type.BOOLEAN)) {
                    _initialValuesSection.setVisible(true);
                    _lblInitialValues.setVisible(true);
                    _itemBooleanValuesModel.bind(model.getInitialValues());
                    _initialBooleanValuesSectionClient.setVisible(true);
                    _initialTextValuesSectionClient.setVisible(false);
                    _initialNumberValuesSectionClient.setVisible(false);
                    _initialValuesSection.setClient(_initialBooleanValuesSectionClient);
                    _initialValuesSection.layout();
                } else if (type.equals(WGContentItemDefinition.Type.NUMBER)) {
                    _initialValuesSection.setVisible(true);
                    _lblInitialValues.setVisible(true);
                    _itemNumberValuesModel.bind(model.getInitialValues());
                    _initialNumberValuesSectionClient.setVisible(true);
                    _initialBooleanValuesSectionClient.setVisible(false);
                    _initialTextValuesSectionClient.setVisible(false);     
                    _initialValuesSection.setClient(_initialNumberValuesSectionClient);
                    _initialValuesSection.layout();
                } else {
                    _initialValuesSection.setVisible(false);
                    _lblInitialValues.setVisible(false);
                }
               
            }
        });
       
        WGContentItemDefinitionModel contentItemDefinitionModel = new WGContentItemDefinitionModel(_model);       
        contentItemDefinitionModel.addListener(new BeanChangedListener<WGContentItemDefinition>() {
            public void changed(WGContentItemDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }           
        });

       
        _subforms.put(SUBFORM_CONTENT_ITEM_DEFINITION, subform);
        _subformModels.put(SUBFORM_CONTENT_ITEM_DEFINITION, contentItemDefinitionModel);

        // content type meta data subforms
        // subform for description
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);       

        parentGroup = createParentInformationGroup(subform);
        parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 2;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Property:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        txtName.setEditable(false);
        Text txtValue = factory.createTextArea(subform, "Description", "description");       
        GridData txtValueLayoutData = new GridData(GridData.FILL_BOTH);
        txtValueLayoutData.minimumHeight = 200;
        txtValue.setLayoutData(txtValueLayoutData)
       
        WGDescriptionMetaFieldDefinitionModel descriptionMetaFieldDefinitionModel = new WGDescriptionMetaFieldDefinitionModel(_model);
        descriptionMetaFieldDefinitionModel.addListener(new BeanChangedListener<WGMetaFieldDefinition>() {
            public void changed(WGMetaFieldDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });
       
        _subforms.put(SUBFORM_META_DESCRIPTION, subform);
        _subformModels.put(SUBFORM_META_DESCRIPTION, descriptionMetaFieldDefinitionModel);
       
        // subform for event scripts
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);       

        parentGroup = createParentInformationGroup(subform);
        parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 2;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Property:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        txtName.setEditable(false);
        txtValue = factory.createTextArea(subform, "Scriptcode:", "code");       
        txtValueLayoutData = new GridData(GridData.FILL_BOTH);
        txtValueLayoutData.minimumHeight = 200;
        txtValue.setLayoutData(txtValueLayoutData)
       
        WGEventScriptMetaFieldDefinitionModel eventScriptMetaFieldDefinitionModel = new WGEventScriptMetaFieldDefinitionModel(_model);
        eventScriptMetaFieldDefinitionModel.addListener(new BeanChangedListener<WGMetaFieldDefinition>() {
            public void changed(WGMetaFieldDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });

       
        _subforms.put(SUBFORM_META_EVENTSCRIPT, subform);
        _subformModels.put(SUBFORM_META_EVENTSCRIPT, eventScriptMetaFieldDefinitionModel);
       
        // subform for layouts
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 3;
        subform.setLayout(subformLayout);
               
        parentGroup = createParentInformationGroup(subform);
        parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 3;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Property:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        txtName.setEditable(false);
        factory.addFiller(subform);
        txtValue = factory.createText(subform, "Module:", "layout");              
        txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        final Text fTxtLayout = txtValue;
        Button btnBrowseLayout = new Button(subform, SWT.PUSH);
        btnBrowseLayout.setText("browse ...");
        btnBrowseLayout.addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                handleBrowserLayout(fTxtLayout)
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {                            
            }
        });
        WGLayoutMetaFieldDefinitionModel layoutMetaFieldDefinitionModel = new WGLayoutMetaFieldDefinitionModel(_model);
        layoutMetaFieldDefinitionModel.addListener(new BeanChangedListener<WGMetaFieldDefinition>() {
            public void changed(WGMetaFieldDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });

       
        _subforms.put(SUBFORM_META_LAYOUT, subform);
        _subformModels.put(SUBFORM_META_LAYOUT, layoutMetaFieldDefinitionModel);
       
        // subform for allowed positions
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);
               
        parentGroup = createParentInformationGroup(subform);
        parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 2;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Property:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        txtName.setEditable(false);
        Combo comboPositioning = factory.createCombo(subform, "Positions:", "positioning");              
        comboPositioning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        factory.addFiller(subform);
        _tblAllowedPositions = new EditableTableControl<PrimitiveTypeBean<String>>(subform, SWT.NONE);
        _allowedPositionsModel = new PrimitiveTypeBeanListTableModel<String>();
        _allowedPositionsModel.addListener(new BeanListTableModelListener() {
           
            public void update(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void remove(Object bean) {
                _model.fireModelChanged();
            }
           
            public void refresh(List beans) {
            }
           
            public void add(Object bean) {
                _model.fireModelChanged();               
            }
        });
        _tblAllowedPositions.init(new String[] {"Name"}, _allowedPositionsModel);
        GridData tblLayoutData = new GridData(GridData.FILL_BOTH);
        tblLayoutData.minimumHeight = 200;
        _tblAllowedPositions.setLayoutData(tblLayoutData);
        cellEditors = new CellEditor[1];
        cellEditors[0] = new TextCellEditor(_tblAllowedPositions.getTable());
        _tblAllowedPositions.getTableViewer().setCellEditors(cellEditors);
       
        comboPositioning.addModifyListener(new ModifyListener() {
           
            public void modifyText(ModifyEvent e) {
                WGPositioningMetaFieldDefinitionModel model = (WGPositioningMetaFieldDefinitionModel)_subformModels.get(SUBFORM_META_POSITIONING);
                if (model.getPositioning().getKey().equals(WGContentType.POSITIONING_FIXEDPARENTS) || model.getPositioning().getKey().equals(WGContentType.POSITIONING_FIXEDPARENTTYPES)) {
                    _tblAllowedPositions.setVisible(true);
                    WGContentTypeDefinition cTypeDefinition = _model.findContentTypeDefinition(model.getBean());                   
                    ((PrimitiveTypeBeanListTableModel<String>)_tblAllowedPositions.getModel()).bind(model.getAllowedPositions(cTypeDefinition));
                } else {
                    _tblAllowedPositions.setVisible(false);
                }
            }
        });

        _tblAllowedPositions.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleAdd(_tblAllowedPositions, "<value>");
            }
        });

        _tblAllowedPositions.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleRemove(_tblAllowedPositions);
            }
        });
       
           
        WGPositioningMetaFieldDefinitionModel positioningMetaFieldDefinitionModel = new WGPositioningMetaFieldDefinitionModel(_model);
        positioningMetaFieldDefinitionModel.addListener(new BeanChangedListener<WGMetaFieldDefinition>() {
            public void changed(WGMetaFieldDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });

       
        _subforms.put(SUBFORM_META_POSITIONING, subform);
        _subformModels.put(SUBFORM_META_POSITIONING, positioningMetaFieldDefinitionModel);
       
       
        // subform for editors
        subform = toolkit.createComposite(_detailSection);
        subformLayout = new GridLayout();  
        subformLayout.numColumns = 2;
        subform.setLayout(subformLayout);
               
        parentGroup = createParentInformationGroup(subform);
        parentInfoLayoutData = new GridData(GridData.FILL_HORIZONTAL);       
        parentInfoLayoutData.horizontalSpan = 2;
        parentGroup.setLayoutData(parentInfoLayoutData);
       
        txtName = factory.createText(subform, "Property:", "name");
        txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        txtName.setEditable(false);
        Label label = new Label(subform, SWT.NONE);
        label.setText("Editors:");
        label.setLayoutData(new GridData(SWT.NONE, SWT.BEGINNING, false, false));
        _tblEditors = new EditableTableControl<PrimitiveTypeBean<String>>(subform, SWT.NONE);
        _editorsModel = new PrimitiveTypeBeanListTableModel<String>();
       
        _editorsModel.addListener(new BeanListTableModelListener() {
           
            public void update(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void remove(Object bean) {
                _model.fireModelChanged();               
            }
           
            public void refresh(List beans) {
                // TODO Auto-generated method stub
               
            }
           
            public void add(Object bean) {
                _model.fireModelChanged();               
            }
        });
       
        _tblEditors.init(new String[] {"Editor"}, _editorsModel);
        tblLayoutData = new GridData(GridData.FILL_BOTH);
        tblLayoutData.minimumHeight = 200;
        _tblEditors.setLayoutData(tblLayoutData);
        cellEditors = new CellEditor[1];
        cellEditors[0] = new TextCellEditor(_tblEditors.getTable());
        _tblEditors.getTableViewer().setCellEditors(cellEditors);
       
       
        _tblEditors.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleAdd(_tblEditors, "<editor/ role name>");
            }
        });

        _tblEditors.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                handleRemove(_tblEditors);
            }
        });
       
           
        WGEditorsMetaFieldDefinitionModel editorsMetaFieldDefinitionModel = new WGEditorsMetaFieldDefinitionModel(_model);
        editorsMetaFieldDefinitionModel.addListener(new BeanChangedListener<WGMetaFieldDefinition>() {
            public void changed(WGMetaFieldDefinition bean) {
                _treeViewer.refresh(bean, true);
                _model.fireModelChanged();
            }
        });
       
        _subforms.put(SUBFORM_META_EDITORS, subform);
        _subformModels.put(SUBFORM_META_EDITORS, editorsMetaFieldDefinitionModel);
       
       
        _model.addListener(new WGASchemaDefinitionModelListener() {           
            public void modelChanged() {
                _treeViewer.refresh();
                _detailSection.setVisible(false);
            }
        });
       
        _detailSection.setVisible(false);
    }

    protected void handleBrowserLayout(Text textControl) {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(Display.getCurrent().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        IFile syncInfo = ((IFileEditorInput)getEditorInput()).getFile();
        WGADesignStructureHelper helper = new WGADesignStructureHelper(syncInfo);       
        dialog.setInput(helper.getTmlRoot());
        dialog.setAllowMultiple(false);
        dialog.setHelpAvailable(false);
        dialog.setTitle("TML layout selection");
        dialog.setValidator(new ISelectionStatusValidator() {
           
            public IStatus validate(Object[] selection) {
                if (selection != null && selection.length == 1) {
                    if (selection[0] instanceof IFile) {
                        return new Status(Status.OK, Plugin.PLUGIN_ID, ((IFile)selection[0]).getFullPath().toString());
                    }
                }
                return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Please select a tml layout file.");
            }
        });
        // first try to find reference in medium "html" - otherwise check all available mediaKeys in design
        IFile preSelection = helper.findReferencedTMLModule(textControl.getText(), "html");
        if (preSelection == null) {
            for (String mediaKey : helper.getMediaKeys()) {
                preSelection = helper.findReferencedTMLModule(textControl.getText(), mediaKey);
                if (preSelection != null) {
                    break;
                }
            }
        }
        if (preSelection != null) {
            dialog.setInitialSelection(preSelection);
        }
        int result = dialog.open();
        if (result == Dialog.OK) {
            IFile selection = (IFile) dialog.getFirstResult();
            textControl.setText(helper.computeTMLReference(selection));
        }
    }

    private Group createParentInformationGroup(Composite subform) {
        Group parentInfo = new Group(subform, SWT.BORDER);
        parentInfo.setLayout(new GridLayout(2, false));
        parentInfo.setText("Parent");
       
        Label lblContentTypeName = new Label(parentInfo, SWT.NONE);
        lblContentTypeName.setText("Contenttype:");
        Text txtContentTypeName = new Text(parentInfo, SWT.NONE);
        txtContentTypeName.setEditable(false);
        txtContentTypeName.setData("contentTypeName");
        txtContentTypeName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 
        Label lblActions = new Label(parentInfo, SWT.NONE);
        lblActions.setText("Actions:");
        HyperlinkGroup parentActionGroup = new HyperlinkGroup(Display.getCurrent());
        Hyperlink defineMetas = new Hyperlink(parentInfo, SWT.NONE);
        defineMetas.setText("add properties...");
        defineMetas.addHyperlinkListener(new IHyperlinkListener() {
           
            public void linkExited(HyperlinkEvent e) {
                // TODO Auto-generated method stub
               
            }
           
            public void linkEntered(HyperlinkEvent e) {
                // TODO Auto-generated method stub
               
            }
           
            public void linkActivated(HyperlinkEvent e) {
                handleAddMetaDataDefinition();               
            }
        });
        parentActionGroup.add(defineMetas);
        Label lbl = new Label(parentInfo, SWT.NONE);
        Hyperlink defineItems = new Hyperlink(parentInfo, SWT.NONE);
        defineItems.setText("add item definition...");
        defineItems.addHyperlinkListener(new IHyperlinkListener() {
           
            public void linkExited(HyperlinkEvent e) {
                // TODO Auto-generated method stub
               
            }
           
            public void linkEntered(HyperlinkEvent e) {
                // TODO Auto-generated method stub
               
            }
           
            public void linkActivated(HyperlinkEvent e) {
                handleAddItemDefinition();               
            }

        });
        parentActionGroup.add(defineItems);
        return parentInfo;
    }
   
    protected void handleAddItemDefinition() {
        ISelection selection = _treeViewer.getSelection();
        if (selection != null && selection instanceof TreeSelection) {
            TreeSelection structuredSelection = (TreeSelection) selection;
            Object node = structuredSelection.getFirstElement();
            WGContentTypeDefinition cTypeDefinition = retrieveCurrentContentTypeDefinition();
            if (cTypeDefinition != null) {
                WGContentItemDefinition itemDef = new WGContentItemDefinition();
                itemDef.setName("<name>");
                itemDef.setType(WGContentItemDefinition.Type.TEXT);
                cTypeDefinition.addContentItemDefinition(itemDef);
                _treeViewer.refresh(cTypeDefinition, true);
                _treeViewer.expandToLevel(itemDef, 1);
                _treeViewer.setSelection(new SingleStructuredSelection(itemDef));
                _model.fireModelChanged();
            }
        }
    }

    protected void handleAddMetaDataDefinition() {
        WGContentTypeDefinition cTypeDef = retrieveCurrentContentTypeDefinition();
        if (cTypeDef != null) {
            AddContentTypeMetaDefinitionDialog dialog = new AddContentTypeMetaDefinitionDialog(Display.getCurrent().getActiveShell(), cTypeDef);
            dialog.setTitle("Content Type properties");
            int result = dialog.open();
            if (result == Dialog.OK) {
                if (dialog.getDefinitionsToAdd().size() > 0) {
                    List<WGMetaFieldDefinition> defs = dialog.getDefinitionsToAdd();
                    Collections.sort(defs, new Comparator<WGMetaFieldDefinition>() {

                        public int compare(WGMetaFieldDefinition o1, WGMetaFieldDefinition o2) {
                            return o1.getName().compareTo(o2.getName());
                        }
                    });
                    cTypeDef.getMetadata().addAll(defs);                   
                    _treeViewer.refresh(cTypeDef, true);
                    _treeViewer.expandToLevel(defs.get(0), 1);
                    _treeViewer.setSelection(new SingleStructuredSelection(defs.get(0)));
                    _model.fireModelChanged();
                }
            }
        }
    }

    protected WGContentTypeDefinition retrieveCurrentContentTypeDefinition() {
        if (_treeViewer != null) {
            TreeSelection treeSelection = (TreeSelection) _treeViewer.getSelection();
            if (!treeSelection.isEmpty()) {
                Object element = treeSelection.getFirstElement();
                if (element instanceof WGContentTypeDefinition) {
                    return (WGContentTypeDefinition) element;
                } else if (element instanceof WGMetaFieldDefinition) {
                    return _model.findContentTypeDefinition((WGMetaFieldDefinition)element);
                } else if (element instanceof WGContentItemDefinition) {
                    return _model.findContentTypeDefinition((WGContentItemDefinition)element);
                }
            }
        }
        return null;
    }

    public void selectionChanged(SelectionChangedEvent e) {
        ISelection selection = e.getSelection();
        if (selection != null && selection instanceof TreeSelection) {
            TreeSelection structuredSelection = (TreeSelection) selection;
            Object node = structuredSelection.getFirstElement();
            if (node instanceof WGContentTypeDefinition) {
                _detailSection.setText("Content Type Definition");
                switchToSubform(SUBFORM_CONTENT_TYPE_DEFINITION, node);
            } else if (node instanceof WGAreaDefinition) {
                _detailSection.setText("Area Definition");
                switchToSubform(SUBFORM_AREA_DEFINITION, node);
            } else if (node instanceof WGLanguageDefinition) {               
                _detailSection.setText("Language Definition");
                switchToSubform(SUBFORM_LANGUAGE_DEFINITION, node);
            } else if (node instanceof WGContentItemDefinition) {               
                _detailSection.setText("Item Definition");
                switchToSubform(SUBFORM_CONTENT_ITEM_DEFINITION, node);
            } else if (node instanceof WGMetaFieldDefinition) {
                WGMetaFieldDefinition def = (WGMetaFieldDefinition) node;
                if (def.getName().startsWith("EVENT")) {
                    _detailSection.setText("Property (Event Script)");
                    switchToSubform(SUBFORM_META_EVENTSCRIPT, node);
                } else if (def.getName().endsWith("LAYOUT")) {
                    _detailSection.setText("Property (Layout)");
                    switchToSubform(SUBFORM_META_LAYOUT, node);
                } else if (def.getName().equals("POSITIONING")) {
                    _detailSection.setText("Property (Positioning)");
                    switchToSubform(SUBFORM_META_POSITIONING, node);                  
                } else if (def.getName().equals(WGContentType.META_EDITORS)) {
                    _detailSection.setText("Property (Editors)");                   
                    WGEditorsMetaFieldDefinitionModel model = (WGEditorsMetaFieldDefinitionModel) _subformModels.get(SUBFORM_META_EDITORS);
                    WGContentTypeDefinition cTypeDefinition = _model.findContentTypeDefinition((WGMetaFieldDefinition)node)
                    ((PrimitiveTypeBeanListTableModel<String>)_tblEditors.getModel()).bind(model.getEditors(cTypeDefinition));
                    switchToSubform(SUBFORM_META_EDITORS, node);
                } else if (def.getName().equals(WGContentType.META_DESCRIPTION)) {
                    _detailSection.setText("Property (Description)");
                    switchToSubform(SUBFORM_META_DESCRIPTION, node);                     
                }
                // todo check for CT-meta
//                _detailSection.setText("Meta Field Definition");
//                switchToSubform(_frmMetaFieldDefinition);
//                _wgMetaFieldDefinitionModel.setBean((WGMetaFieldDefinition)node);
//                _wgMetaFieldDefinitionModel.bind(_frmMetaFieldDefinition, this);                               
//                _detailSection.layout();
            } else {
                _detailSection.setVisible(false);
            }
        }
       
    }
   
    @SuppressWarnings("unchecked")
    private void switchToSubform(String subformKey, Object bean) {
        Composite composite = _subforms.get(subformKey);
        for (Composite control : _subforms.values()) {
            if (control == composite) {               
                control.setVisible(true);
                GenesisBoundObject model = _subformModels.get(subformKey);
                model.setBean(bean);
                model.bind(control, this, SWTBinder.BINDING_STRATEGY_AS_YOU_TYPE);
                _detailSection.setVisible(true);
                _detailSection.setClient(control);
                _detailSection.layout();
               
                if (bean instanceof WGSchemaDocumentDefinition) {
                    String name = ((WGSchemaDocumentDefinition)bean).getName();
                    if (name != null && name.equals("<name>")) {
                        for (Control subControl : control.getChildren()) {
                            if (subControl.getData() != null && subControl.getData().equals("name")) {
                                subControl.setFocus();
                                if (subControl instanceof Text) {
                                    ((Text)subControl).selectAll();
                                }
                                break;
                            }
                        }
                    }
                } else if (bean instanceof WGContentItemDefinition) {
                    String name = ((WGContentItemDefinition)bean).getName();
                    if (name != null && name.equals("<name>")) {
                        for (Control subControl : control.getChildren()) {
                            if (subControl.getData() != null && subControl.getData().equals("name")) {
                                subControl.setFocus();
                                if (subControl instanceof Text) {
                                    ((Text)subControl).selectAll();
                                }
                                break;
                            }
                        }
                    }
                }
               
            } else {
                control.setVisible(false);
            }
        }
    }

    @SuppressWarnings("unchecked")
    protected void handleRemove(EditableTableControl control) {
        if (control.getTable().getSelectionCount() > 0) {
            control.getModel().remove((PrimitiveTypeBean)control.getTable().getSelection()[0].getData());
        }
    }

    protected void handleAdd(EditableTableControl<PrimitiveTypeBean<String>> control, String value) {
        control.getModel().add(new PrimitiveTypeBean<String>(value));
    }
   
    protected void handleAdd(EditableTableControl<PrimitiveTypeBean<Boolean>> control, boolean value) {
        control.getModel().add(new PrimitiveTypeBean<Boolean>(value));
    }

    protected void handleAdd(EditableTableControl<PrimitiveTypeBean<Number>> control, Number value) {
        control.getModel().add(new PrimitiveTypeBean<Number>(value));
    }
   

    @Override
    public void refresh() throws IOException {
        super.refresh();
        _treeViewer.setInput(_model);
        _treeViewer.refresh(true);
    }
   
   
}
TOP

Related Classes of de.innovationgate.eclipse.editors.design.pages.SchemaConfigurationPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.