-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.charts.ui;\r
-\r
-import java.awt.Color;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.action.ContributionItem;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.jface.resource.JFaceResources;\r
-import org.eclipse.jface.resource.LocalResourceManager;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.swt.widgets.MenuItem;\r
-import org.simantics.Simantics;\r
-import org.simantics.charts.Activator;\r
-import org.simantics.charts.query.ChartItemIndexQuery;\r
-import org.simantics.charts.query.SetChartItemIndexRequest;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-public class SetIndexItem extends ContributionItem implements SelectionListener {\r
-\r
- int index;\r
- Color color;\r
- String label;\r
- Image image;\r
- LocalResourceManager rm;\r
- List<Resource> chartItems;\r
- boolean analogIcon; \r
- \r
- public SetIndexItem(Color color, int index, String label, boolean analogIcon, List<Resource> chartItems)\r
- {\r
- super("org.simantics.charts.ui.ColorItem."+index);\r
- this.index = index;\r
- this.label = label;\r
- this.color = color;\r
- this.chartItems = chartItems;\r
- this.analogIcon = analogIcon;\r
- }\r
- \r
- @Override\r
- public void fill(Menu menu, int index) {\r
- \r
- MenuItem item = new MenuItem(menu, SWT.CHECK);\r
-// item.setText( this.index+":"+label );\r
- item.setText( this.index+"" );\r
- item.addSelectionListener(this);\r
-\r
- boolean selected = false;\r
- if (chartItems.size()==1) {\r
- try {\r
- Integer selIndex = Simantics.getSession().sync( new ChartItemIndexQuery(chartItems.get(0)) );\r
- selected = (selIndex!=null) && (this.index == selIndex);\r
- } catch (DatabaseException e) {\r
- }\r
- }\r
- \r
- item.setSelection( selected );\r
- if (rm==null) rm = new LocalResourceManager(JFaceResources.getResources());\r
- \r
- ImageDescriptor icon = Activator.getDefault().chartIcons.createIcon(analogIcon, color, selected);\r
- \r
- image = (Image) rm.get(icon);\r
- item.setImage( image );\r
- }\r
- \r
- @Override\r
- public void dispose() {\r
- if (rm != null) rm.dispose();\r
- super.dispose();\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- for ( Resource chartItem : chartItems) {\r
- Session s = Simantics.getSession();\r
- s.markUndoPoint();\r
- s.async( new SetChartItemIndexRequest(chartItem, index) );\r
- }\r
- }\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- widgetSelected(e);\r
- }\r
- \r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.ui;
+
+import java.awt.Color;
+import java.util.List;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.simantics.Simantics;
+import org.simantics.charts.Activator;
+import org.simantics.charts.query.ChartItemIndexQuery;
+import org.simantics.charts.query.SetChartItemIndexRequest;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+
+public class SetIndexItem extends ContributionItem implements SelectionListener {
+
+ int index;
+ Color color;
+ String label;
+ Image image;
+ LocalResourceManager rm;
+ List<Resource> chartItems;
+ boolean analogIcon;
+
+ public SetIndexItem(Color color, int index, String label, boolean analogIcon, List<Resource> chartItems)
+ {
+ super("org.simantics.charts.ui.ColorItem."+index);
+ this.index = index;
+ this.label = label;
+ this.color = color;
+ this.chartItems = chartItems;
+ this.analogIcon = analogIcon;
+ }
+
+ @Override
+ public void fill(Menu menu, int index) {
+
+ MenuItem item = new MenuItem(menu, SWT.CHECK);
+// item.setText( this.index+":"+label );
+ item.setText( this.index+"" );
+ item.addSelectionListener(this);
+
+ boolean selected = false;
+ if (chartItems.size()==1) {
+ try {
+ Integer selIndex = Simantics.getSession().sync( new ChartItemIndexQuery(chartItems.get(0)) );
+ selected = (selIndex!=null) && (this.index == selIndex);
+ } catch (DatabaseException e) {
+ }
+ }
+
+ item.setSelection( selected );
+ if (rm==null) rm = new LocalResourceManager(JFaceResources.getResources());
+
+ ImageDescriptor icon = Activator.getDefault().chartIcons.createIcon(analogIcon, color, selected);
+
+ image = (Image) rm.get(icon);
+ item.setImage( image );
+ }
+
+ @Override
+ public void dispose() {
+ if (rm != null) rm.dispose();
+ super.dispose();
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ for ( Resource chartItem : chartItems) {
+ Session s = Simantics.getSession();
+ s.markUndoPoint();
+ s.async( new SetChartItemIndexRequest(chartItem, index) );
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
}
\ No newline at end of file