/*******************************************************************************
* Copyright (c) 2012 Olivier Moises
*
* 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:
* Olivier Moises- initial API and implementation
*******************************************************************************/
package org.eclipse.wazaabi.engine.swt.snippets;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wazaabi.engine.swt.nonosgi.SWTHelper;
import org.eclipse.wazaabi.engine.swt.viewers.SWTControlViewer;
import org.eclipse.wazaabi.locationpaths.nonosgi.LocationPathsHelper;
import org.eclipse.wazaabi.mm.core.Orientation;
import org.eclipse.wazaabi.mm.core.styles.BooleanRule;
import org.eclipse.wazaabi.mm.core.styles.CoreStylesFactory;
import org.eclipse.wazaabi.mm.core.styles.collections.ColumnDescriptor;
import org.eclipse.wazaabi.mm.core.styles.collections.CoreCollectionsStylesFactory;
import org.eclipse.wazaabi.mm.core.styles.collections.LookAndFeel;
import org.eclipse.wazaabi.mm.core.styles.collections.LookAndFeelRule;
import org.eclipse.wazaabi.mm.core.styles.collections.PathSelector;
import org.eclipse.wazaabi.mm.core.widgets.Collection;
import org.eclipse.wazaabi.mm.core.widgets.Container;
import org.eclipse.wazaabi.mm.core.widgets.CoreWidgetsFactory;
import org.eclipse.wazaabi.mm.core.widgets.CoreWidgetsPackage;
import org.eclipse.wazaabi.mm.swt.styles.RowDataRule;
import org.eclipse.wazaabi.mm.swt.styles.RowLayoutRule;
import org.eclipse.wazaabi.mm.swt.styles.SWTStylesFactory;
public class CollectionOfEObjectsUsingSetFeatureAnnotation {
public static void main(String[] args) {
// create the shell
Display display = new Display();
Shell mainShell = new Shell(display, SWT.SHELL_TRIM);
mainShell.setLayout(new FillLayout());
mainShell.setSize(400, 400);
// create the viewer
SWTControlViewer viewer = new SWTControlViewer(mainShell);
// init SWT Engine in standalone mode
SWTHelper.init(viewer);
// initialize the locationPaths processor
LocationPathsHelper.init(viewer);
// create a container and set its layout
Container container = CoreWidgetsFactory.eINSTANCE.createContainer();
RowLayoutRule layoutRule = SWTStylesFactory.eINSTANCE
.createRowLayoutRule();
layoutRule.setPropertyName("layout");
container.getStyleRules().add(layoutRule);
// create a collection
final Collection collection = CoreWidgetsFactory.eINSTANCE
.createCollection();
BooleanRule booleanRule = CoreStylesFactory.eINSTANCE
.createBooleanRule();
booleanRule.setValue(true);
// booleanRule.setPropertyName("allow-row-selection");
// booleanRule.setPropertyName("show-horizontal-lines");
booleanRule.setPropertyName("header-visible");
collection.getStyleRules().add(booleanRule);
collection.setAnnotation("http://www.wazaabi.org/set-feature",
"feature-name", "input");
collection.setAnnotation("http://www.wazaabi.org/set-feature", "type",
"locationpath");
collection.setAnnotation("http://www.wazaabi.org/set-feature", "value",
"eClassifier('http://www.wazaabi.org/core', 'Orientation')");
LookAndFeelRule lookAndFeelRule = CoreCollectionsStylesFactory.eINSTANCE
.createLookAndFeelRule();
lookAndFeelRule.setPropertyName("lookandfeel"); //$NON-NLS-1$
lookAndFeelRule.setValue(LookAndFeel.COMBOBOX);
collection.getStyleRules().add(lookAndFeelRule);
RowDataRule rowDataRule = SWTStylesFactory.eINSTANCE
.createRowDataRule();
rowDataRule.setPropertyName("layout-data");
rowDataRule.setHeight(250);
rowDataRule.setWidth(150);
PathSelector pathSelector1 = CoreCollectionsStylesFactory.eINSTANCE
.createPathSelector();
pathSelector1.setPropertyName("content-provider");
pathSelector1.setEClassifierName("EEnum");
pathSelector1.getPaths().add("&eLiterals/@instance");
collection.getStyleRules().add(pathSelector1);
collection.getStyleRules().add(rowDataRule);
ColumnDescriptor columnDescriptor1 = CoreCollectionsStylesFactory.eINSTANCE
.createColumnDescriptor();
columnDescriptor1.setLabel("test1");
columnDescriptor1.setPropertyName("column-descriptor");
columnDescriptor1.setWidth(100);
collection.getStyleRules().add(columnDescriptor1);
// append the collection to the container's children list.
container.getChildren().add(collection);
collection.eAdapters().add(new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
switch (msg.getFeatureID(Collection.class)) {
case CoreWidgetsPackage.COLLECTION__SELECTION:
if (msg.getEventType() == Notification.ADD)
System.out.println("add:" + msg.getNewValue());
if (msg.getEventType() == Notification.REMOVE)
System.out.println("remove:" + msg.getOldValue());
}
}
});
collection.getSelection().add(Orientation.VERTICAL);
// inject the container into the viewer
viewer.setContents(container);
collection.getSelection().add(Orientation.HORIZONTAL);
// collection.getSelection().clear();
mainShell.open();
while (!mainShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}