Fixed taxonomic tree to reflect current data source.
authorp.ciardelli <p.ciardelli@localhost>
Tue, 17 Mar 2009 14:53:47 +0000 (14:53 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Tue, 17 Mar 2009 14:53:47 +0000 (14:53 +0000)
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/type/TypeCollectionPropertySource.java

index 53c5e89e509440eddc32f441e5fd42688d5f1150..2bf0b5345d2d277b50505e48bfdba3c56896745d 100644 (file)
@@ -431,10 +431,12 @@ public class CdmDataSourceDialog extends Dialog {
        }\r
 \r
        private void testDbConfig() {\r
+               \r
+               \r
                ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance(\r
                                serverText.getText(),\r
-                               databaseNameText.getText(), \r
-                               Integer.valueOf(portText.getText()), \r
+                               databaseNameText.getText(),\r
+                               getPort(), \r
                                usernameText.getText(), \r
                                passwordText.getText());\r
                if (dataSource.testConnection()) {\r
@@ -444,6 +446,18 @@ public class CdmDataSourceDialog extends Dialog {
                }\r
        }\r
 \r
+       /**\r
+        * @return\r
+        */\r
+       private int getPort() {\r
+               try {\r
+                       return Integer.valueOf(portText.getText());\r
+               } catch (NumberFormatException e) {\r
+                       portText.setText("");\r
+                       return -1;\r
+               }\r
+       }\r
+\r
        private void saveDbConfig() {\r
                \r
                // Get field values\r
@@ -453,14 +467,9 @@ public class CdmDataSourceDialog extends Dialog {
                String database = databaseNameText.getText();\r
                String username = usernameText.getText(); \r
                String password = passwordText.getText();\r
+               Integer port = getPort(); // new Integer(portText.getText());\r
                \r
-               try {\r
-                       \r
-                       // Try casting port to an integer\r
-                       Integer port = new Integer(portText.getText());\r
-                       \r
-                       logger.warn(port);\r
-                       \r
+               if (port > 0) {\r
                        // Save with port\r
                        CdmDataSourceRepository.getDefault().save (\r
                                        dataSourceName, \r
@@ -469,19 +478,45 @@ public class CdmDataSourceDialog extends Dialog {
                                        database, \r
                                        port, \r
                                        username, \r
-                                       password);\r
-                       \r
-               } catch (ClassCastException e) {\r
-                       \r
-                       // If cast failed, save without port\r
+                                       password);                      \r
+               } else {\r
+                       // Save without port\r
                        CdmDataSourceRepository.getDefault().save (\r
                                        dataSourceName, \r
                                        databaseType, \r
                                        server, \r
                                        database,\r
                                        username, \r
-                                       password);\r
+                                       password);                      \r
                }\r
+//             try {\r
+//                     \r
+//                     // Try casting port to an integer\r
+//                     Integer port = new Integer(portText.getText());\r
+//                     \r
+//                     logger.warn(port);\r
+//                     \r
+//                     // Save with port\r
+//                     CdmDataSourceRepository.getDefault().save (\r
+//                                     dataSourceName, \r
+//                                     databaseType, \r
+//                                     server, \r
+//                                     database, \r
+//                                     port, \r
+//                                     username, \r
+//                                     password);\r
+//                     \r
+//             } catch (ClassCastException e) {\r
+//                     \r
+//                     // If cast failed, save without port\r
+//                     CdmDataSourceRepository.getDefault().save (\r
+//                                     dataSourceName, \r
+//                                     databaseType, \r
+//                                     server, \r
+//                                     database,\r
+//                                     username, \r
+//                                     password);\r
+//             }\r
                \r
                // Refresh list of data sources to reflect changes\r
                refreshDataSourceViewer();\r
index ba377a11f0c02a2336a1fdd532a02edc5bd3f562..3d8ff7fe222d4e2366dccb964a3827185ef89838 100644 (file)
@@ -163,8 +163,8 @@ public class CdmDataSourceRepository implements ICdmDataSourceRepository {
                                        monitor.worked(1);\r
                                                                                \r
                                        try {\r
-                                               getCdmAppController().changeDataSource(dataSource);\r
-//                                             getCdmAppController().changeDataSource(dataSource, DbSchemaValidation.CREATE);\r
+//                                             getCdmAppController().changeDataSource(dataSource);\r
+                                               getCdmAppController().changeDataSource(dataSource, DbSchemaValidation.UPDATE);\r
                                        } catch (TermNotFoundException e) {\r
                                                // TODO Auto-generated catch block\r
                                                e.printStackTrace();\r
index 1fe790c0402330ee1cc4a47ab8e3229b74231d03..b6b3c90793bbd19bb1571498058e723332e6dab1 100644 (file)
@@ -13,11 +13,11 @@ import java.util.List;
 \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
@@ -45,7 +45,6 @@ import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
 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
@@ -64,12 +63,17 @@ public class TaxonomicTreeView extends ViewPart {
        \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
@@ -77,35 +81,40 @@ public class TaxonomicTreeView extends ViewPart {
         */\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
@@ -113,20 +122,25 @@ public class TaxonomicTreeView extends ViewPart {
                // 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
@@ -165,6 +179,19 @@ public class TaxonomicTreeView extends ViewPart {
                \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
@@ -173,11 +200,7 @@ public class TaxonomicTreeView extends ViewPart {
                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
@@ -185,6 +208,14 @@ public class TaxonomicTreeView extends ViewPart {
                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
@@ -212,12 +243,13 @@ public class TaxonomicTreeView extends ViewPart {
                        }\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
@@ -252,11 +284,27 @@ public class TaxonomicTreeView extends ViewPart {
                                                        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
@@ -299,3 +347,4 @@ public class TaxonomicTreeView extends ViewPart {
                return treeViewer;\r
        }\r
 }\r
+\r
index 3e296cb8d8defb9c48cb1eb9c7b840388b826671..86bf36e66e9f10c001c67c4aac5216eb0abd2e91 100644 (file)
@@ -76,7 +76,14 @@ public class TypeCollectionPropertySource extends CollectionPropertySource {
                                                        }                                                       \r
                                                    }\r
                                                    protected Object doGetValue() {\r
-                                                       return editorValue;\r
+                                                       \r
+//                                                     if (editorValue instanceof TypeCollectionPropertySource) {\r
+//                                                             String cache = \r
+//                                                     }\r
+//                                                     \r
+//                                                     if (super.doGetValue().equals())\r
+//                                                     return editorValue;\r
+                                                       return super.doGetValue();\r
                                                    }\r
                                                };\r
                                                if (getValidator() != null) {\r
@@ -211,5 +218,19 @@ public class TypeCollectionPropertySource extends CollectionPropertySource {
                        \r
                        return null;\r
                }\r
+               \r
+               public boolean equals(Object object) {\r
+                       if (object == null) {\r
+                               return false;\r
+                       }\r
+                       if (toString() == null) {\r
+                               return false;\r
+                       }\r
+                       if (toString().equals(object.toString())) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               }\r
        }\r
 }
\ No newline at end of file