\r
import org.apache.log4j.Logger;\r
import org.eclipse.jface.action.GroupMarker;\r
-import org.eclipse.jface.action.IMenuManager;\r
-import org.eclipse.jface.action.IToolBarManager;\r
import org.eclipse.jface.action.MenuManager;\r
import org.eclipse.jface.dialogs.Dialog;\r
import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.MouseAdapter;\r
+import org.eclipse.swt.events.MouseEvent;\r
import org.eclipse.swt.events.SelectionAdapter;\r
import org.eclipse.swt.events.SelectionEvent;\r
import org.eclipse.swt.layout.FillLayout;\r
import eu.etaxonomy.cdm.database.ICdmDataSource;\r
import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
-import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction;\r
import eu.etaxonomy.taxeditor.controller.EditorController;\r
import eu.etaxonomy.taxeditor.controller.GlobalController;\r
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceDialog;\r
\r
private Composite dbComposite;\r
private Composite taxTreeComposite = null;\r
- private Composite top = null;\r
public static final String ID = "eu.etaxonomy.taxeditor.navigation.taxonomictreeview"; //$NON-NLS-1$\r
\r
private TaxonomicTreeViewer treeViewer;\r
private IManagedForm hyperlinkForm;\r
private Menu dataSourceMenu;\r
+\r
+ private Label lblDataSource;\r
+\r
+ private Label lblDataSourceTitle;\r
+\r
+ private Composite dbCompositeSub;\r
\r
/**\r
* Create contents of the view part\r
*/\r
@Override\r
public void createPartControl(Composite parent) {\r
- \r
- // Layout top composite\r
- parent.setLayout(new FillLayout());\r
+ \r
+ // Create top composite\r
+ FillLayout fillLayout = new FillLayout();\r
+ fillLayout.marginWidth = 0;\r
+ fillLayout.marginHeight = 0;\r
+ fillLayout.type = SWT.VERTICAL; \r
+ parent.setLayout(fillLayout);\r
+\r
+ // Create composite for DB\r
+ dbComposite = new Composite(parent, SWT.NONE);\r
+ dbComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
GridLayout gridLayout = new GridLayout();\r
gridLayout.horizontalSpacing = 0;\r
gridLayout.marginWidth = 0;\r
gridLayout.marginHeight = 0;\r
- gridLayout.verticalSpacing = 0; \r
- \r
- // Create top composite\r
- top = new Composite(parent, SWT.NONE);\r
- top.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- top.setLayout(gridLayout);\r
+ gridLayout.verticalSpacing = 5; \r
+ dbComposite.setLayout(gridLayout); \r
+ dbComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
+ \r
+ dbCompositeSub = new Composite(dbComposite, SWT.NULL);\r
+ dbCompositeSub.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
+ dbCompositeSub.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
+ GridLayout gridLayout1 = new GridLayout();\r
+ gridLayout1.numColumns = 2;\r
+ dbCompositeSub.setLayout(gridLayout1);\r
\r
- // Create composite for DB\r
- dbComposite = new Composite(top, SWT.NONE);\r
- dbComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- final GridLayout gridLayout_1 = new GridLayout();\r
- gridLayout_1.numColumns = 2;\r
- dbComposite.setLayout(gridLayout_1);\r
- final Label lblDataSourceTitle = new Label(dbComposite, SWT.NONE);\r
+ lblDataSourceTitle = new Label(dbCompositeSub, SWT.NONE);\r
lblDataSourceTitle.setFont(SWTResourceManager.getFont("Arial", 14, SWT.BOLD));\r
lblDataSourceTitle.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
lblDataSourceTitle.setAlignment(SWT.CENTER);\r
- lblDataSourceTitle.setText(" Local"); \r
\r
// Create DB label\r
- final Label lblDatasourceMenu = new Label(dbComposite, SWT.NONE);\r
- lblDatasourceMenu.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
+ final Label lblDatasourceMenu = new Label(dbCompositeSub, SWT.NONE);\r
+ lblDatasourceMenu.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));\r
lblDatasourceMenu.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
lblDatasourceMenu.setImage(ResourceManager.getPluginImage(TaxEditorPlugin.getDefault(), "icons/db.gif"));\r
lblDatasourceMenu.setImage(TaxEditorPlugin.getDefault().getImageRegistry().get(ITaxEditorConstants.DB_ICON));\r
// Create menu to hang from DB label\r
dataSourceMenu = new Menu(lblDatasourceMenu);\r
lblDatasourceMenu.setMenu(dataSourceMenu);\r
+ lblDatasourceMenu.addMouseListener(new MouseAdapter() {\r
+ public void mouseDown(MouseEvent e) {\r
+ dataSourceMenu.setVisible(true);\r
+ }\r
+ });\r
createDataSourceMenu();\r
\r
- // Show current DB\r
- final Label lblDataSource = new Label(dbComposite, SWT.NONE);\r
- final GridData gd_lblDataSource = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);\r
- gd_lblDataSource.heightHint = 16;\r
+ // Create string "jdbc:mysql://192. ..."\r
+ lblDataSource = new Label(dbCompositeSub, SWT.WRAP); \r
+ final GridData gd_lblDataSource = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);\r
+ gd_lblDataSource.horizontalIndent = 5;\r
lblDataSource.setLayoutData(gd_lblDataSource);\r
lblDataSource.setFont(SWTResourceManager.getFont("Arial", 8, SWT.NONE));\r
lblDataSource.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
- lblDataSource.setAlignment(SWT.CENTER);\r
- lblDataSource.setText(" Datasource: local h2 database");\r
+ \r
+ setDataSourceText();\r
\r
// Create composite for taxonomic tree\r
- taxTreeComposite = new Composite(top, SWT.NONE);\r
+ taxTreeComposite = new Composite(dbComposite, SWT.NONE);\r
taxTreeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
taxTreeComposite.setLayout(new FillLayout());\r
taxTreeComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));\r
\r
}\r
\r
+ /**\r
+ * \r
+ */\r
+ private void setDataSourceText() {\r
+ ICdmDataSource dataSource = CdmDataSourceRepository.getDefault().getCurrentDataSource();\r
+ \r
+ lblDataSource.setText(dataSource.getDatabaseType().getConnectionString(dataSource));\r
+ lblDataSourceTitle.setText(getDataSourceName(dataSource));\r
+\r
+ dbCompositeSub.layout();\r
+ dbComposite.layout();\r
+ }\r
+\r
private void createDataSourceMenu() {\r
\r
// Create entry to open data source dialog\r
newDataSourceMenuItem.setText("Edit data sources ...");\r
newDataSourceMenuItem.addSelectionListener(new SelectionAdapter() {\r
public void widgetSelected(SelectionEvent event) {\r
- Dialog dialog = new CdmDataSourceDialog(GlobalController.getShell());\r
- dialog.open();\r
- \r
- // Refresh menu to reflect any changes in data \r
- refreshDataSources();\r
+ showDataSourceDialog();\r
}\r
});\r
\r
refreshDataSources();\r
}\r
\r
+ private void showDataSourceDialog() {\r
+ Dialog dialog = new CdmDataSourceDialog(GlobalController.getShell());\r
+ dialog.open();\r
+ \r
+ // Refresh menu to reflect any changes in data \r
+ refreshDataSources();\r
+ }\r
+ \r
private void refreshDataSources() {\r
\r
// First dispose of any entries that are already there\r
}\r
\r
// Make a nice little name string out of this mutha\r
- String text = dataSource.getName();\r
- if (!dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)) {\r
- if (dataSource.getDatabase() != null) {\r
- text += " (" + dataSource.getDatabaseType().getName() + ")";\r
- }\r
- }\r
+// String text = dataSource.getName();\r
+// if (!dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)) {\r
+// if (dataSource.getDatabase() != null) {\r
+// text += " (" + dataSource.getDatabaseType().getName() + ")";\r
+// }\r
+// }\r
+ String text = getDataSourceName(dataSource);\r
item.setText(text);\r
item.setData(dataSource);\r
\r
item.setSelection(false);\r
}\r
}\r
+ \r
+ setDataSourceText();\r
}\r
});\r
}\r
}\r
\r
+ /**\r
+ * @param dataSource\r
+ * @return\r
+ */\r
+ private String getDataSourceName(ICdmDataSource dataSource) {\r
+ String text = dataSource.getName();\r
+ if (!dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)) {\r
+ if (dataSource.getDatabase() != null) {\r
+ text += " (" + dataSource.getDatabaseType().getName() + ")";\r
+ }\r
+ }\r
+ return text;\r
+ }\r
+\r
public TaxonomicTreeViewer createTreeViewer() {\r
\r
// Dispose link to new taxon as necessary\r
return treeViewer;\r
}\r
}\r
+\r