00001 package org.swtchart.ext.internal.properties;
00002
00003 import org.eclipse.swt.SWT;
00004 import org.eclipse.swt.events.SelectionAdapter;
00005 import org.eclipse.swt.events.SelectionEvent;
00006 import org.eclipse.swt.layout.GridData;
00007 import org.eclipse.swt.layout.GridLayout;
00008 import org.eclipse.swt.widgets.Composite;
00009 import org.eclipse.swt.widgets.Control;
00010 import org.eclipse.swt.widgets.Label;
00011 import org.eclipse.swt.widgets.List;
00012 import org.swtchart.ext.InteractiveChart;
00013
00017 abstract public class AbstractSelectorPage extends AbstractPage {
00018
00020 protected List list;
00021
00023 private String selector;
00024
00026 private boolean selectorEnabled;
00027
00029 protected int selectedIndex;
00030
00043 public AbstractSelectorPage(InteractiveChart chart,
00044 PropertiesResources resources, String title, String selector) {
00045 super(chart, resources, title);
00046 this.selector = selector;
00047 selectedIndex = 0;
00048 selectorEnabled = true;
00049 }
00050
00051
00052
00053
00054 @Override
00055 protected Control createContents(Composite parent) {
00056 String[] items = getListItems();
00057 if (items.length < 2) {
00058 selectorEnabled = false;
00059 }
00060
00061 Composite composite = new Composite(parent, SWT.NONE);
00062 if (selectorEnabled) {
00063 GridLayout layout = new GridLayout(3, true);
00064 layout.marginHeight = 0;
00065 layout.marginWidth = 0;
00066 composite.setLayout(layout);
00067
00068 Label label = new Label(composite, SWT.NULL);
00069 label.setText(selector);
00070 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
00071 gridData.horizontalSpan = 3;
00072 label.setLayoutData(gridData);
00073
00074 addLeftPanel(composite, items);
00075 addRightPanel(composite);
00076 } else {
00077 GridLayout layout = new GridLayout(1, true);
00078 layout.marginHeight = 0;
00079 layout.marginWidth = 0;
00080 composite.setLayout(layout);
00081 addRightPanelContents(composite);
00082 }
00083
00084 selectInitialValues();
00085 updateControlSelections();
00086
00087 return composite;
00088 }
00089
00095 abstract protected String[] getListItems();
00096
00100 abstract protected void selectInitialValues();
00101
00110 private void addLeftPanel(Composite parent, String[] items) {
00111 Composite leftPanel = new Composite(parent, SWT.NULL);
00112 GridData gridData = new GridData(GridData.FILL_BOTH);
00113 gridData.horizontalSpan = 1;
00114 leftPanel.setLayoutData(gridData);
00115
00116 GridLayout layout = new GridLayout(1, false);
00117 layout.marginHeight = 0;
00118 layout.marginWidth = 0;
00119 leftPanel.setLayout(layout);
00120
00121 list = new List(leftPanel, SWT.BORDER);
00122 GridData gridData2 = new GridData(GridData.FILL_BOTH);
00123 gridData2.horizontalSpan = 1;
00124 list.setLayoutData(gridData2);
00125 for (String item : items) {
00126 list.add(item);
00127 }
00128
00129 list.addSelectionListener(new SelectionAdapter() {
00130 @Override
00131 public void widgetSelected(SelectionEvent e) {
00132 selectedIndex = list.getSelectionIndex();
00133 updateControlSelections();
00134 }
00135 });
00136 list.select(0);
00137 }
00138
00145 private void addRightPanel(Composite parent) {
00146 Composite rightPanel = new Composite(parent, SWT.NULL);
00147 GridData gridData = new GridData(GridData.FILL_BOTH);
00148 gridData.horizontalSpan = 2;
00149 rightPanel.setLayoutData(gridData);
00150 rightPanel.setLayout(new GridLayout(1, false));
00151
00152 addRightPanelContents(rightPanel);
00153 }
00154
00161 abstract protected void addRightPanelContents(Composite parent);
00162
00166 abstract protected void updateControlSelections();
00167 }