/*******************************************************************************
* 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.dialogs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import de.innovationgate.eclipse.utils.ui.ValidatedDialog;
import de.innovationgate.webgate.api.WGContentType;
import de.innovationgate.webgate.api.schemadef.WGContentTypeDefinition;
import de.innovationgate.webgate.api.schemadef.WGMetaFieldDefinition;
public class AddContentTypeMetaDefinitionDialog extends ValidatedDialog {
private WGContentTypeDefinition _contentTypeDefinition;
private List<WGMetaFieldDefinition> _definitionsToAdd = new ArrayList<WGMetaFieldDefinition>();
private List<Button> _checkBoxes = new ArrayList<Button>();
private static Map<String,WGMetaFieldDefinition> METADATA_DEFINITIONS = new LinkedHashMap<String, WGMetaFieldDefinition>();
static {
METADATA_DEFINITIONS.put(WGContentType.META_POSITIONING, new WGMetaFieldDefinition(WGContentType.META_POSITIONING, null));
METADATA_DEFINITIONS.put(WGContentType.META_DESCRIPTION, new WGMetaFieldDefinition(WGContentType.META_DESCRIPTION, null));
METADATA_DEFINITIONS.put(WGContentType.META_EDITORS, new WGMetaFieldDefinition(WGContentType.META_EDITORS, null));
METADATA_DEFINITIONS.put(WGContentType.META_EVENT_CREATECONTENT, new WGMetaFieldDefinition(WGContentType.META_EVENT_CREATECONTENT, null));
METADATA_DEFINITIONS.put(WGContentType.META_EVENT_SAVECONTENT, new WGMetaFieldDefinition(WGContentType.META_EVENT_SAVECONTENT, null));
METADATA_DEFINITIONS.put(WGContentType.META_EVENT_WORKFLOWMAIL, new WGMetaFieldDefinition(WGContentType.META_EVENT_WORKFLOWMAIL, null));
METADATA_DEFINITIONS.put(WGContentType.META_INNER_LAYOUT, new WGMetaFieldDefinition(WGContentType.META_INNER_LAYOUT, null));
METADATA_DEFINITIONS.put(WGContentType.META_OUTER_LAYOUT, new WGMetaFieldDefinition(WGContentType.META_OUTER_LAYOUT, null));
}
public static Map<String,String> METADATA_DEFINITION_LABELS = new HashMap<String, String>();
static {
METADATA_DEFINITION_LABELS.put(WGContentType.META_DESCRIPTION, "Description");
METADATA_DEFINITION_LABELS.put(WGContentType.META_EDITORS, "Editors");
METADATA_DEFINITION_LABELS.put(WGContentType.META_EVENT_CREATECONTENT, "Eventscript (create content)");
METADATA_DEFINITION_LABELS.put(WGContentType.META_EVENT_SAVECONTENT, "Eventscript (save content)");
METADATA_DEFINITION_LABELS.put(WGContentType.META_EVENT_WORKFLOWMAIL, "Eventscript (send workflow mail)");
METADATA_DEFINITION_LABELS.put(WGContentType.META_INNER_LAYOUT, "Innerlayout");
METADATA_DEFINITION_LABELS.put(WGContentType.META_OUTER_LAYOUT, "Outerlayout");
METADATA_DEFINITION_LABELS.put(WGContentType.META_POSITIONING, "Allowed positions");
}
public AddContentTypeMetaDefinitionDialog(Shell parent, WGContentTypeDefinition def) {
super(parent);
setHelpAvailable(false);
_contentTypeDefinition = def;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.None);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
new Label(composite, SWT.NONE).setText("Add properties to content type");
new Label(composite, SWT.NONE);
for (WGMetaFieldDefinition def : METADATA_DEFINITIONS.values()) {
Button checkMetaData = new Button(composite, SWT.CHECK);
checkMetaData.setText(METADATA_DEFINITION_LABELS.get(def.getName()));
if (hasMetaDataDefinition(_contentTypeDefinition, def)) {
checkMetaData.setSelection(true);
checkMetaData.setEnabled(false);
}
checkMetaData.setData(def);
_checkBoxes.add(checkMetaData);
}
return composite;
}
private boolean hasMetaDataDefinition(WGContentTypeDefinition contentTypeDefinition, WGMetaFieldDefinition def) {
for (WGMetaFieldDefinition metaDef : contentTypeDefinition.getMetadata()) {
if (metaDef.getName().equals(def.getName())) {
return true;
}
}
return false;
}
@Override
public void computeResponse() {
for (Button checkBox : _checkBoxes) {
if (checkBox.isEnabled() && checkBox.getSelection()) {
WGMetaFieldDefinition def = new WGMetaFieldDefinition(((WGMetaFieldDefinition)checkBox.getData()).getName(), null);
_definitionsToAdd.add(def);
}
}
}
@Override
public List<String> validate() {
return Collections.emptyList();
}
public List<WGMetaFieldDefinition> getDefinitionsToAdd() {
return _definitionsToAdd ;
}
}