/*******************************************************************************
* 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.models;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import de.innovationgate.eclipse.utils.ui.model.WGASchemaDefinitionModel;
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;
public class WGASchemaDefinitionContentProvider implements ITreeContentProvider {
private WGASchemaDefinitionModel _model;
public static String CONTENTTYPE_DEFINITIONS_ROOT = "Content Type Definitions";
public static String AREA_DEFINITIONS_ROOT = "Area Definitions";
public static String LANGUAGE_DEFINITIONS_ROOT = "Language Definitions";
private static String[] ROOTS = new String[] {CONTENTTYPE_DEFINITIONS_ROOT, AREA_DEFINITIONS_ROOT, LANGUAGE_DEFINITIONS_ROOT};
private static String[] CONTENT_TYPE_METAS = new String[] {"EVENTSAVECONTENT", "OUTERLAYOUT", "EDITORS", "INNERLAYOUT", "EVENTCREATECONTENT", "POSITIONING", "EVENTWORKFLOWMAIL", "DESCRIPTION"};
public Object[] getChildren(Object node) {
if (node instanceof String) {
if (node.equals(CONTENTTYPE_DEFINITIONS_ROOT)) {
return _model.getContentTypeDefinitions().toArray();
} else if (node.equals(AREA_DEFINITIONS_ROOT)) {
return _model.getAreaDefinitions().toArray();
} else if (node.equals(LANGUAGE_DEFINITIONS_ROOT)) {
return _model.getLanguageDefinitions().toArray();
}
} else if (node instanceof WGContentTypeDefinition) {
WGContentTypeDefinition def = (WGContentTypeDefinition) node;
List<Object> childs = new ArrayList<Object>();
Iterator<WGMetaFieldDefinition> metaFieldDefs = def.getMetadata().iterator();
while (metaFieldDefs.hasNext()) {
WGMetaFieldDefinition metaFieldDef = metaFieldDefs.next();
if (Arrays.asList(CONTENT_TYPE_METAS).contains(metaFieldDef.getName())) {
childs.add(metaFieldDef);
}
}
//childs.addAll(def.getContentMetaDefinitions());
childs.addAll(def.getContentItemDefinitions());
return childs.toArray();
}
return null;
}
public Object getParent(Object node) {
if (node instanceof WGContentTypeDefinition) {
return CONTENTTYPE_DEFINITIONS_ROOT;
} else if (node instanceof WGLanguageDefinition) {
return LANGUAGE_DEFINITIONS_ROOT;
} else if (node instanceof WGAreaDefinition) {
return AREA_DEFINITIONS_ROOT;
} else if (node instanceof WGContentItemDefinition) {
WGContentItemDefinition def = (WGContentItemDefinition)node;
Iterator<WGContentTypeDefinition> ctDefs = _model.getContentTypeDefinitions().iterator();
while (ctDefs.hasNext()) {
WGContentTypeDefinition ctDef = ctDefs.next();
if (ctDef.getContentItemDefinitions().contains(def)) {
return ctDef;
}
}
} else if (node instanceof WGMetaFieldDefinition) {
WGMetaFieldDefinition def = (WGMetaFieldDefinition)node;
Iterator<WGContentTypeDefinition> ctDefs = _model.getContentTypeDefinitions().iterator();
while (ctDefs.hasNext()) {
WGContentTypeDefinition ctDef = ctDefs.next();
if (ctDef.getContentMetaDefinitions().contains(def) || ctDef.getMetadata().contains(def)) {
return ctDef;
}
}
}
return null;
}
public boolean hasChildren(Object node) {
if (node instanceof String) {
if (node.equals(CONTENTTYPE_DEFINITIONS_ROOT)) {
return _model.getContentTypeDefinitions().size() > 0;
} else if (node.equals(AREA_DEFINITIONS_ROOT)) {
return _model.getAreaDefinitions().size() > 0;
} else if (node.equals(LANGUAGE_DEFINITIONS_ROOT)) {
return _model.getLanguageDefinitions().size() > 0;
}
} else if (node instanceof WGContentTypeDefinition) {
WGContentTypeDefinition def = (WGContentTypeDefinition) node;
return def.getContentItemDefinitions().size() > 0 || def.getContentMetaDefinitions().size() > 0 || def.getMetadata().size() > 0;
}
return false;
}
public Object[] getElements(Object input) {
if (input == null || !(input instanceof WGASchemaDefinitionModel)) {
return null;
} else {
_model = (WGASchemaDefinitionModel)input;
return ROOTS;
}
}
public void dispose() {
}
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// TODO Auto-generated method stub
}
}