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);