1 package eu
.etaxonomy
.taxeditor
.prototype1
.view
;
3 import org
.eclipse
.core
.databinding
.DataBindingContext
;
4 import org
.eclipse
.core
.databinding
.beans
.BeansObservables
;
5 import org
.eclipse
.core
.databinding
.observable
.Realm
;
6 import org
.eclipse
.core
.databinding
.observable
.list
.IObservableList
;
7 import org
.eclipse
.core
.databinding
.observable
.map
.IObservableMap
;
8 import org
.eclipse
.jface
.action
.IMenuManager
;
9 import org
.eclipse
.jface
.action
.IToolBarManager
;
10 import org
.eclipse
.jface
.databinding
.viewers
.ObservableListContentProvider
;
11 import org
.eclipse
.jface
.databinding
.viewers
.ObservableMapLabelProvider
;
12 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
13 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
14 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
15 import org
.eclipse
.jface
.viewers
.TableViewer
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.layout
.GridData
;
18 import org
.eclipse
.swt
.layout
.GridLayout
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.ExpandBar
;
21 import org
.eclipse
.swt
.widgets
.ExpandItem
;
22 import org
.eclipse
.swt
.widgets
.Table
;
23 import org
.eclipse
.ui
.part
.ViewPart
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
26 import eu
.etaxonomy
.taxeditor
.prototype1
.Activator
;
27 import eu
.etaxonomy
.taxeditor
.prototype1
.controller
.OpenNameEditorAction
;
29 public class NameListView
extends ViewPart
{
31 private Composite nameListComposite
= null;
32 private Composite recentNamesComposite
= null;
33 private Composite searchComposite
= null;
34 private Composite top
= null;
35 private ExpandBar expandBar
= null;
36 private TableViewer viewer
;
37 private ExpandItem nameListExpandItem
;
38 private ExpandItem recentNamesExpandItem
;
39 private ExpandItem searchExpandItem
;
40 public static final String ID
= "eu.etaxonomy.mvctest.view.NameListView"; //$NON-NLS-1$
43 * Create contents of the view part
47 public void createPartControl(Composite parent
) {
49 GridLayout gridLayout
= new GridLayout();
50 gridLayout
.horizontalSpacing
= 0;
51 gridLayout
.marginWidth
= 0;
52 gridLayout
.marginHeight
= 0;
53 gridLayout
.verticalSpacing
= 0;
54 top
= new Composite(parent
, SWT
.NONE
);
56 top
.setLayout(gridLayout
);
60 * This method initializes expandBar
63 private void createExpandBar() {
64 expandBar
= new ExpandBar(top
, SWT
.NONE
);
65 GridData gridData
= new GridData();
66 gridData
.horizontalAlignment
= GridData
.FILL
;
67 gridData
.grabExcessHorizontalSpace
= true;
68 gridData
.grabExcessVerticalSpace
= true;
69 gridData
.verticalAlignment
= GridData
.FILL
;
70 expandBar
.setLayoutData(gridData
);
71 createNameListComposite();
72 createRecentNamesComposite();
73 createSearchComposite();
81 private void createNameListComposite() {
82 nameListExpandItem
= new ExpandItem(expandBar
, SWT
.NONE
, 0);
83 nameListExpandItem
.setHeight(500);
85 nameListExpandItem
.setText("Name List");
86 nameListExpandItem
.setExpanded(true);
87 // Image image = FileArrangerImages.getImageRegistry().get(
88 // IFileArrangerImages.IMG_HOME);
89 // nameListExpandItem.setImage(image);
91 nameListComposite
= new Composite(expandBar
, SWT
.NONE
);
92 // nameListExpandItem.setHeight(nameListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
93 GridLayout layout
= new GridLayout();
94 layout
.verticalSpacing
= 0;
95 layout
.marginWidth
= 0;
96 layout
.marginHeight
= 0;
97 layout
.horizontalSpacing
= 0;
98 // layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
99 // layout.verticalSpacing = 5;
100 nameListComposite
.setLayout(layout
);
102 viewer
= new TableViewer(nameListComposite
, SWT
.H_SCROLL
104 table
= viewer
.getTable();
105 final GridData gd_table
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
106 // gd_table.heightHint = 238;
107 // gd_table.widthHint = 443;
108 table
.setLayoutData(gd_table
);
110 viewer
.addDoubleClickListener(new IDoubleClickListener(){
112 public void doubleClick(DoubleClickEvent event
) {
113 TaxonName taxonname
= null;
115 taxonname
= (TaxonName
) ((StructuredSelection
)event
.getSelection()).getFirstElement();
116 }catch (Exception e
){
120 new OpenNameEditorAction(taxonname
).run();
124 nameListExpandItem
.setControl(nameListComposite
);
128 private void createRecentNamesComposite() {
129 recentNamesExpandItem
= new ExpandItem(expandBar
, SWT
.NONE
, 1);
130 recentNamesExpandItem
.setExpanded(true);
131 recentNamesExpandItem
.setText("Recently viewed names");
132 recentNamesComposite
= new Composite(expandBar
, SWT
.NONE
);
133 GridLayout layout
= new GridLayout();
134 layout
.marginLeft
= layout
.marginTop
= layout
.marginRight
= layout
.marginBottom
= 10;
135 layout
.verticalSpacing
= 5;
136 recentNamesComposite
.setLayout(layout
);
138 recentNamesExpandItem
.setHeight(recentNamesComposite
.computeSize(
139 SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
140 recentNamesExpandItem
.setControl(recentNamesComposite
);
142 // Image image = FileArrangerImages.getImageRegistry().get(
143 // IFileArrangerImages.IMG_BOOKMARK);
144 // bookmarksExpandItem.setImage(image);
147 private void createSearchComposite() {
148 searchExpandItem
= new ExpandItem(expandBar
, SWT
.NONE
, 2);
149 searchExpandItem
.setHeight(200);
150 searchExpandItem
.setExpanded(true);
151 searchExpandItem
.setText("Search");
152 searchComposite
= new Composite(expandBar
, SWT
.NONE
);
153 final GridLayout gridLayout
= new GridLayout();
154 searchComposite
.setLayout(gridLayout
);
156 searchExpandItem
.setControl(searchComposite
);
159 // Image image = FileArrangerImages.getImageRegistry().get(
160 // IFileArrangerImages.IMG_FTP);
161 // ftpExpandItem.setImage(image);
164 private void createActions() {
165 // Create the actions
169 * Initialize the toolbar
171 private void initializeToolBar() {
172 IToolBarManager toolbarManager
= getViewSite().getActionBars()
173 .getToolBarManager();
177 * Initialize the menu
179 private void initializeMenu() {
180 IMenuManager menuManager
= getViewSite().getActionBars()
185 public void setFocus() {
189 protected DataBindingContext
initDataBindings() {
191 ObservableListContentProvider viewerContentProviderList
= new ObservableListContentProvider();
192 viewer
.setContentProvider(viewerContentProviderList
);
194 IObservableMap
[] viewerLabelProviderMaps
= BeansObservables
.observeMaps(viewerContentProviderList
.getKnownElements(), TaxonName
.class, new String
[]{"name"});
195 viewer
.setLabelProvider(new ObservableMapLabelProvider(viewerLabelProviderMaps
));
197 IObservableList olObjectListObserveList
= BeansObservables
.observeList(Realm
.getDefault(), Activator
.getDefault().getObjectList(), "objectList");
198 viewer
.setInput(olObjectListObserveList
);
200 DataBindingContext bindingContext
= new DataBindingContext();
203 return bindingContext
;