p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.prototype2 / src / eu / etaxonomy / taxeditor / prototype2 / view / NameListView.java
1 package eu.etaxonomy.taxeditor.prototype2.view;
2
3 import org.eclipse.jface.action.IMenuManager;
4 import org.eclipse.jface.action.IToolBarManager;
5 import org.eclipse.jface.viewers.TableViewer;
6 import org.eclipse.jface.viewers.TreeViewer;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.FocusEvent;
9 import org.eclipse.swt.events.FocusListener;
10 import org.eclipse.swt.layout.FillLayout;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.swt.widgets.ExpandBar;
18 import org.eclipse.swt.widgets.ExpandItem;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Menu;
21 import org.eclipse.swt.widgets.MenuItem;
22 import org.eclipse.swt.widgets.Text;
23 import org.eclipse.ui.part.ViewPart;
24
25 import com.swtdesigner.ResourceManager;
26 import com.swtdesigner.SWTResourceManager;
27
28 import eu.etaxonomy.taxeditor.prototype2.Activator;
29
30 /**
31 * @author p.ciardelli
32 *
33 */
34 public class NameListView extends ViewPart {
35
36 private Text searchText;
37 private Composite composite;
38 private Composite taxTreeComposite = null;
39 private Composite recentNamesComposite = null;
40 private Composite searchComposite = null;
41 private Composite top = null;
42 private ExpandBar expandBar = null;
43 private ExpandItem taxTreeExpandItem;
44 private ExpandItem recentNamesExpandItem;
45 private ExpandItem searchExpandItem;
46 private TableViewer recentNamesViewer;
47 public static final String ID = "eu.etaxonomy.taxeditor.prototype2.view.namelistview"; //$NON-NLS-1$
48
49 private TreeViewer treeViewer;
50
51 /**
52 * Create contents of the view part
53 * @param parent
54 */
55 @Override
56 public void createPartControl(Composite parent) {
57
58 parent.setLayout(new FillLayout());
59 GridLayout gridLayout = new GridLayout();
60 gridLayout.horizontalSpacing = 0;
61 gridLayout.marginWidth = 0;
62 gridLayout.marginHeight = 0;
63 gridLayout.verticalSpacing = 0;
64
65 top = new Composite(parent, SWT.NONE);
66 top.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
67
68 composite = new Composite(top, SWT.NONE);
69 composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
70 final GridLayout gridLayout_1 = new GridLayout();
71 gridLayout_1.numColumns = 2;
72 composite.setLayout(gridLayout_1);
73 final Label lblDataSourceTitle = new Label(composite, SWT.NONE);
74 lblDataSourceTitle.setFont(SWTResourceManager.getFont("Arial", 14, SWT.BOLD));
75 lblDataSourceTitle.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
76 lblDataSourceTitle.setAlignment(SWT.CENTER);
77 lblDataSourceTitle.setText(" Euro+Med");
78
79 final Label lblDbImg = new Label(composite, SWT.NONE);
80 lblDbImg.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
81 lblDbImg.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
82 lblDbImg.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/db.gif"));
83
84 final Menu menu = new Menu(lblDbImg);
85 lblDbImg.setMenu(menu);
86
87 final MenuItem checkboxMenuItem = new MenuItem(menu, SWT.CHECK);
88 checkboxMenuItem.setSelection(true);
89 checkboxMenuItem.setText("Euro+Med (mssql://128.14.101.12:80/europlusmed)");
90
91 final MenuItem checkboxMenuItem_1 = new MenuItem(menu, SWT.CHECK);
92 checkboxMenuItem_1.setText("WP6 (mssql://128.14.101.13:80/wp6)");
93
94 final MenuItem palmWebora1922299480pwMenuItem = new MenuItem(menu, SWT.NONE);
95 palmWebora1922299480pwMenuItem.setText("Palm Web (ora://192.22.99.4:80/pw)");
96
97 new MenuItem(menu, SWT.SEPARATOR);
98
99 final MenuItem newDataSourceMenuItem = new MenuItem(menu, SWT.NONE);
100 newDataSourceMenuItem.setText("New data source ...");
101
102 final Label lblDataSource = new Label(composite, SWT.NONE);
103 final GridData gd_lblDataSource = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
104 gd_lblDataSource.heightHint = 16;
105 lblDataSource.setLayoutData(gd_lblDataSource);
106 lblDataSource.setFont(SWTResourceManager.getFont("Arial", 8, SWT.NONE));
107 lblDataSource.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
108 lblDataSource.setAlignment(SWT.CENTER);
109 lblDataSource.setText(" mssql://128.14.101.12:80/europlusmed");
110
111 createExpandBar();
112 top.setLayout(gridLayout);
113 top.setTabList(new Control[] {composite, expandBar});
114 }
115
116 /**
117 * This method initializes expandBar
118 *
119 */
120 private void createExpandBar() {
121 expandBar = new ExpandBar(top, SWT.V_SCROLL);
122 GridData gridData = new GridData();
123 gridData.horizontalAlignment = GridData.FILL;
124 gridData.grabExcessHorizontalSpace = true;
125 gridData.grabExcessVerticalSpace = true;
126 gridData.verticalAlignment = GridData.FILL;
127 expandBar.setLayoutData(gridData);
128 createNameListComposite();
129 createRecentNamesComposite();
130 createSearchComposite();
131
132 createActions();
133 initializeToolBar();
134 initializeMenu();
135
136 }
137
138 private void createNameListComposite() {
139 taxTreeExpandItem = new ExpandItem(expandBar, SWT.NONE, 0);
140 taxTreeExpandItem.setExpanded(true);
141 taxTreeExpandItem.setHeight(200);
142 taxTreeExpandItem.setText("Taxonomic Tree");
143
144 taxTreeComposite = new Composite(expandBar, SWT.NONE);
145 taxTreeComposite.setLayout(new FillLayout());
146 taxTreeComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
147
148 taxTreeExpandItem.setControl(taxTreeComposite);
149
150 treeViewer = new TaxonomicTreeViewer(taxTreeComposite);
151 }
152
153 private void createRecentNamesComposite() {
154 recentNamesExpandItem = new ExpandItem(expandBar, SWT.NONE, 1);
155 recentNamesExpandItem.setHeight(130);
156 recentNamesExpandItem.setExpanded(true);
157 recentNamesExpandItem.setText("Recently viewed names");
158 recentNamesComposite = new Composite(expandBar, SWT.NONE);
159 recentNamesComposite.setLayout(new GridLayout());
160
161 recentNamesExpandItem.setControl(recentNamesComposite);
162
163 recentNamesViewer = new RecentNamesTableViewer(recentNamesComposite);
164 }
165
166 private void createSearchComposite() {
167 searchExpandItem = new ExpandItem(expandBar, SWT.NONE, 2);
168 searchExpandItem.setHeight(50);
169 searchExpandItem.setExpanded(true);
170 searchExpandItem.setText("Search");
171 searchComposite = new Composite(expandBar, SWT.NONE);
172 final GridLayout gridLayout = new GridLayout();
173 gridLayout.numColumns = 2;
174 searchComposite.setLayout(gridLayout);
175
176 searchExpandItem.setControl(searchComposite);
177
178 searchText = new Text(searchComposite, SWT.BORDER);
179 searchText.setForeground(SWTResourceManager.getColor(192, 192, 192));
180 searchText.setText("Use \"*\" for wildcard searching");
181 final GridData gd_useForText = new GridData(SWT.FILL, SWT.CENTER, true, false);
182 searchText.setLayoutData(gd_useForText);
183 searchText.addFocusListener(new FocusListener() {
184
185 public void focusGained(FocusEvent e) {
186 searchText.setForeground(SWTResourceManager.getColor(0,0,0));
187 searchText.setText("");
188 }
189
190 public void focusLost(FocusEvent e) {
191 if (searchText.getText() == "") {
192 searchText.setForeground(SWTResourceManager.getColor(192, 192, 192));
193 searchText.setText("Use \"*\" for wildcard searching");
194 }
195
196 }
197
198 });
199
200 final Button searchButton = new Button(searchComposite, SWT.NONE);
201 searchButton.setText("Search");
202
203 // Image image = FileArrangerImages.getImageRegistry().get(
204 // IFileArrangerImages.IMG_FTP);
205 // ftpExpandItem.setImage(image);
206 }
207
208 private void createActions() {
209 // Create the actions
210 }
211
212 /**
213 * Initialize the toolbar
214 */
215 private void initializeToolBar() {
216 IToolBarManager toolbarManager = getViewSite().getActionBars()
217 .getToolBarManager();
218 }
219
220 /**
221 * Initialize the menu
222 */
223 private void initializeMenu() {
224 IMenuManager menuManager = getViewSite().getActionBars()
225 .getMenuManager();
226 }
227
228 @Override
229 public void setFocus() {
230 // Set the focus
231 }
232
233 /**
234 * Expose TreeViewer, i.e. to manipulate tree nodes
235 * @return
236 */
237 public TreeViewer getTreeViewer() {
238 return treeViewer;
239 }
240
241 }