From f8c060f1b198422a55d746900d0c37e4bcbe0338 Mon Sep 17 00:00:00 2001 From: "p.ciardelli" Date: Tue, 7 Oct 2008 13:29:33 +0000 Subject: [PATCH] Added "Save All" button which saves all open taxon editors, commits the current transaction, and starts a new transaction. --- .gitattributes | 5 +- .../ApplicationWorkbenchWindowAdvisor.java | 3 +- .../FreetextPropertiesPerspective.java | 15 +- .../taxeditor/SideBySidePerspective.java | 12 +- .../etaxonomy/taxeditor/TaxEditorPlugin.java | 78 ++++-- .../src/eu/etaxonomy/taxeditor/UiUtil.java | 20 ++ .../taxeditor/actions/SaveAllAction.java | 78 ++++++ .../CreateNewHeterotypicCompositeAction.java | 10 +- .../actions/ui/OpenTaxonEditorAction.java | 2 +- .../datasource/CdmDataSourceDialog.java | 233 ++++++++++++++++ .../datasource/CopyOfCdmDataSourceDialog.java | 254 ++++++++++++++++++ .../RegisterDatabaseDialog.java | 2 +- .../editor/AbstractTaxonEditorView.java | 9 +- .../editor/EditorGroupedComposite.java | 8 + .../taxeditor/editor/name/NameComposite.java | 3 +- .../eu/etaxonomy/taxeditor/model/CdmUtil.java | 4 +- .../navigation/TaxonomicTreeView.java | 91 ++++--- .../name/NonViralNamePropertySource.java | 9 +- 18 files changed, 738 insertions(+), 98 deletions(-) create mode 100644 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java create mode 100644 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java create mode 100644 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CopyOfCdmDataSourceDialog.java rename eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/{editor => datasource}/RegisterDatabaseDialog.java (96%) diff --git a/.gitattributes b/.gitattributes index 133728a68..58738b4b1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -398,6 +398,7 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePers eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/NameTransfer.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SynonymRelationshipTransfer.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/TaxonTransfer.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/UndoableAction.java -text @@ -443,6 +444,9 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/Ope eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/RemoveBasionymCompositeAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/AddDescriptionElementCompositeAction.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/description/DeleteElementCompositeAction.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CopyOfCdmDataSourceDialog.java -text +eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/RegisterDatabaseDialog.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditorView.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AnnotationMarkerAccess.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/CompositeBorderDecorator.java -text @@ -466,7 +470,6 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/LineWra eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/ParseListener.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/PropertySheetViewer.java -text -eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/RegisterDatabaseDialog.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/SelectTaxonDialog.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/SimpleSelectionProvider.java -text eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/UndoView.java -text diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java index 5dcdf9103..83b0758de 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java @@ -10,7 +10,6 @@ package eu.etaxonomy.taxeditor; import org.apache.log4j.Logger; -import org.eclipse.jface.action.IContributionItem; import org.eclipse.swt.graphics.Point; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; @@ -38,7 +37,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); // configurer.setInitialSize(new Point(800, 600)); configurer.setInitialSize(new Point(963, 637)); - configurer.setShowCoolBar(false); + configurer.setShowCoolBar(true); configurer.setShowStatusLine(false); configurer.setShowPerspectiveBar(true); configurer.setTitle("EDIT Taxonomic Editor"); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java index 7348cc9d8..715a5c5d4 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java @@ -13,10 +13,9 @@ import org.apache.log4j.Logger; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +import org.eclipse.ui.actions.ActionFactory; -import eu.etaxonomy.taxeditor.navigation.FavoritesView; import eu.etaxonomy.taxeditor.navigation.RecentNamesView; -import eu.etaxonomy.taxeditor.navigation.SearchView; import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView; /** @@ -44,22 +43,16 @@ public class FreetextPropertiesPerspective implements IPerspectiveFactory { IFolderLayout folderLayoutLeft = layout.createFolder("leftfolder", IPageLayout.LEFT, 0.3f, editorArea); folderLayoutLeft.addView(TaxonomicTreeView.ID); - folderLayoutLeft.addView(SearchView.ID); +// folderLayoutLeft.addView(SearchView.ID); IFolderLayout folderLayoutBottomLeft = layout.createFolder("bottomleftfolder", IPageLayout.BOTTOM, 0.75f, "leftfolder"); folderLayoutBottomLeft.addView(RecentNamesView.ID); - folderLayoutBottomLeft.addView(FavoritesView.ID); +// folderLayoutBottomLeft.addView(FavoritesView.ID); IFolderLayout folderLayoutRight = layout.createFolder("rightfolder", IPageLayout.RIGHT, 0.5f, editorArea); folderLayoutRight.addView(IPageLayout.ID_PROP_SHEET); layout.getViewLayout(IPageLayout.ID_PROP_SHEET).setCloseable(false); - layout.getViewLayout(TaxonomicTreeView.ID).setCloseable(false); - - addFastViews(layout); - - } - private void addFastViews(IPageLayout layout) { - System.currentTimeMillis(); + layout.getViewLayout(TaxonomicTreeView.ID).setCloseable(false); } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePerspective.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePerspective.java index 81f02839f..e75c16c48 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePerspective.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/SideBySidePerspective.java @@ -28,18 +28,12 @@ public class SideBySidePerspective implements IPerspectiveFactory { IFolderLayout folderLayoutLeft = layout.createFolder("leftfolder", IPageLayout.LEFT, 0.3f, editorArea); folderLayoutLeft.addView(TaxonomicTreeView.ID); - folderLayoutLeft.addView(SearchView.ID); +// folderLayoutLeft.addView(SearchView.ID); IFolderLayout folderLayoutBottomLeft = layout.createFolder("bottomleftfolder", IPageLayout.BOTTOM, 0.75f, "leftfolder"); folderLayoutBottomLeft.addView(RecentNamesView.ID); - folderLayoutBottomLeft.addView(FavoritesView.ID); +// folderLayoutBottomLeft.addView(FavoritesView.ID); - layout.getViewLayout(TaxonomicTreeView.ID).setCloseable(false); - - addFastViews(layout); - - } - private void addFastViews(IPageLayout layout) { - System.currentTimeMillis(); + layout.getViewLayout(TaxonomicTreeView.ID).setCloseable(false); } } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java index 2cae5399c..4526bf06a 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java @@ -10,9 +10,11 @@ package eu.etaxonomy.taxeditor; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; @@ -46,6 +48,7 @@ import eu.etaxonomy.cdm.api.service.IDescriptionService; import eu.etaxonomy.cdm.api.service.INameService; import eu.etaxonomy.cdm.api.service.ITaxonService; import eu.etaxonomy.cdm.database.CdmDataSource; +import eu.etaxonomy.cdm.database.CdmPersistentDataSource; import eu.etaxonomy.cdm.database.DataSourceNotFoundException; import eu.etaxonomy.cdm.database.DbSchemaValidation; import eu.etaxonomy.cdm.database.ICdmDataSource; @@ -99,12 +102,12 @@ public class TaxEditorPlugin extends AbstractUIPlugin { * The constructor */ public TaxEditorPlugin() { - logger.fatal("Fatal"); - logger.error("Error"); - logger.debug("Debug"); - logger.info("Info"); - logger.warn("Warn"); - logger.trace("Trace"); +// logger.fatal("Fatal"); +// logger.error("Error"); +// logger.debug("Debug"); +// logger.info("Info"); +// logger.warn("Warn"); +// logger.trace("Trace"); } /* @@ -115,9 +118,7 @@ public class TaxEditorPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - - boolean initDatastore = false; - + // If the preferences INITIALIZED has not been set, the IF clause // will return false, i.e. datastore will be initialized first // time the application is run after being installed. @@ -127,7 +128,7 @@ public class TaxEditorPlugin extends AbstractUIPlugin { initialized = getPreferenceStore().getBoolean( ITaxEditorConstants.INITIALIZED); } - + if (!initialized) { logger.warn("Initializing datastore"); @@ -243,18 +244,32 @@ public class TaxEditorPlugin extends AbstractUIPlugin { public CdmApplicationController getCdmApp() { if (cdmApp == null) { try { - ICdmDataSource ds = - CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", ""); -// CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_editor_test1", "edit", "wp5"); - - cdmApp = CdmApplicationController - .NewInstance(ds, dbSchemaValidation); - -// cdmApp = CdmApplicationController -// .NewInstance(dbSchemaValidation); +// cdmApp.getDatabaseService().getDatabaseEnum(); +// cdmApp.getDatabaseService().saveDataSource(strDataSourceName, databaseTypeEnum, server, database, username, password) + +// // Open ds by string +// CdmPersistentDataSource ds = CdmPersistentDataSource.NewInstance(dataSourceName) +// +// // Open default instance +// CdmPersistentDataSource ds = CdmPersistentDataSource.NewDefaultInstance(); +// +// CdmPersistentDataSource.getAllDataSources(); +// +// // Open CdmApp w default DB +// CdmApplicationController.NewInstance(dbSchemaValidation); + +// System.exit(-1); + + cdmDatasource = + CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", ""); +//// CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_editor_test1", "edit", "wp5"); +//// CdmPersistentDataSource.NewLocalHsqlInstance(); + cdmApp = CdmApplicationController + .NewInstance(cdmDatasource, dbSchemaValidation); + +// cdmApp = CdmApplicationController.NewInstance(dbSchemaValidation); startTransaction(); -// Object txStatus = cdmApp.startTransaction(); // cdmApp.commitTransaction((TransactionStatus) txStatus); @@ -306,8 +321,27 @@ public class TaxEditorPlugin extends AbstractUIPlugin { if (descriptionService == null) { descriptionService = getCdmApp().getDescriptionService(); } - return descriptionService; - + return descriptionService; + } + + private List dataSources; + + public List getDataSources() { + if (dataSources == null) { + dataSources = new ArrayList(); + dataSources.add(CdmDataSource. + NewH2EmbeddedInstance("cdm", "sa", "")); + dataSources.add(CdmDataSource. + NewMySqlInstance("192.168.2.10", "cdm_editor_test1", + "edit", "wp5")); + } + return dataSources; + } + + private ICdmDataSource cdmDatasource; + + public ICdmDataSource getCdmDataSource() { + return cdmDatasource; } /*************************************************************************** diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java index 2c647206b..5ad8da1ec 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java @@ -42,6 +42,7 @@ import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.editor.CompositeBorderDecorator; import eu.etaxonomy.taxeditor.editor.EditorGroupComposite; +import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; import eu.etaxonomy.taxeditor.model.CdmUtil; import eu.etaxonomy.taxeditor.model.NameEditorInput; import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView; @@ -98,6 +99,25 @@ public class UiUtil { } return null; } + + /** + * Returns a set of all currently open + * MultiPageTaxonEditors. + * + * @return + */ + public static Set getOpenTaxonEditors() { + + Set taxonEditors = new HashSet(); + + for (IEditorReference reference : getActivePage().getEditorReferences()) { + IEditorPart editor = reference.getEditor(false); + if (editor instanceof MultiPageTaxonEditor) { + taxonEditors.add(editor); + } + } + return taxonEditors; + } public static IEditorPart getEditorByTaxon(Taxon taxon) throws PartInitException { diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java new file mode 100644 index 000000000..d25227c0d --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java @@ -0,0 +1,78 @@ +package eu.etaxonomy.taxeditor.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +import eu.etaxonomy.taxeditor.TaxEditorPlugin; +import eu.etaxonomy.taxeditor.UiUtil; + +/** + * Our sample action implements workbench action delegate. + * The action proxy will be created by the workbench and + * shown in the UI. When the user tries to use the action, + * this delegate will be created and execution will be + * delegated to it. + * @see IWorkbenchWindowActionDelegate + */ +public class SaveAllAction implements IWorkbenchWindowActionDelegate { + private IWorkbenchWindow window; + /** + * The constructor. + */ + public SaveAllAction() { + } + + /** + * The action has been activated. The argument of the + * method represents the 'real' action sitting + * in the workbench UI. + * @see IWorkbenchWindowActionDelegate#run + */ + public void run(IAction action) { + + // Get all open windows + for (IEditorPart taxonEditor : UiUtil.getOpenTaxonEditors()) { + + // Save the dirty ones + if (taxonEditor.isDirty()) { + taxonEditor.doSave(null); + } + } + + // Commit the transaction + TaxEditorPlugin.getDefault().commitTransaction(); + + // Start a new transaction + TaxEditorPlugin.getDefault().startTransaction(); + } + + /** + * Selection in the workbench has been changed. We + * can change the state of the 'real' action here + * if we want, but this can only happen after + * the delegate has been created. + * @see IWorkbenchWindowActionDelegate#selectionChanged + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + /** + * We can use this method to dispose of any system + * resources we previously allocated. + * @see IWorkbenchWindowActionDelegate#dispose + */ + public void dispose() { + } + + /** + * We will cache window object in order to + * be able to provide parent shell for the message dialog. + * @see IWorkbenchWindowActionDelegate#init + */ + public void init(IWorkbenchWindow window) { + this.window = window; + } +} \ No newline at end of file diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/CreateNewHeterotypicCompositeAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/CreateNewHeterotypicCompositeAction.java index db28ed391..c2ef0bf70 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/CreateNewHeterotypicCompositeAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/CreateNewHeterotypicCompositeAction.java @@ -121,8 +121,6 @@ public class CreateNewHeterotypicCompositeAction extends Action { // Create new homotypic group composite Object data = synonym.getName().getHomotypicalGroup(); EditorGroupComposite newGroupComposite = new EditorGroupComposite(grandParent, managedForm, data); -// newGroupComposite.setData(synonym.getName().getHomotypicalGroup()); -// new CompositeBorderDecorator(newGroupComposite, managedForm); // Put new group composite above misapplied names as necessary EditorGroupComposite misappliedNameGroupComposite = UiUtil @@ -131,13 +129,9 @@ public class CreateNewHeterotypicCompositeAction extends Action { newGroupComposite.moveAbove(misappliedNameGroupComposite); } - // Create new heterotypic synonym composite + // Create new heterotypic synonym composite, init w unparsed string NameComposite newNameComposite = new NameComposite(newGroupComposite, managedForm, NameComposite.HETEROTYPIC_SYNONYM, synonym); -// newNameComposite.setData(synonym); -// newNameComposite.transform(DescriptionElementComposite.HETEROTYPIC_SYNONYM); - - // Add border support to DescriptionElementComposite -// newNameComposite.createBorderSupport(); + newNameComposite.setText(synonymText); grandParent.layout(); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java index ef29b99b4..b77979e78 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java @@ -69,7 +69,7 @@ public class OpenTaxonEditorAction extends Action { // new name object with the name class specified in the // preference store, i.e. BotanicalName TaxonNameBase name = CdmUtil.parseFullReference("", null, null); -// BotanicalName name = BotanicalName.NewInstance(Rank.GENUS()); + name.setFullTitleCache("", false); this.taxon = Taxon.NewInstance(name, CdmUtil.getSessionDefaultSec()); } else { diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java new file mode 100644 index 000000000..2f7660bad --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CdmDataSourceDialog.java @@ -0,0 +1,233 @@ +package eu.etaxonomy.taxeditor.datasource; + +import org.apache.log4j.Logger; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import eu.etaxonomy.cdm.database.CdmDataSource; +import eu.etaxonomy.cdm.database.DatabaseTypeEnum; +import eu.etaxonomy.cdm.database.ICdmDataSource; +import eu.etaxonomy.taxeditor.TaxEditorPlugin; + +public class CdmDataSourceDialog extends Dialog { + private List list; + private List list_1; + private Text text_6; + private Text text_5; + private Text text_4; + private Text text_2; + private Text text_3; + private Text text; + private static final Logger logger = Logger + .getLogger(CdmDataSourceDialog.class); + private CCombo datasourceTypesCombo; + private Composite composite; + private Composite container; + + /** + * Create the dialog + * @param parentShell + */ + public CdmDataSourceDialog(Shell parentShell) { + super(parentShell); + } + + /** + * Create contents of the dialog + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + container = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + container.setLayout(gridLayout); + + final ListViewer listViewer = new ListViewer(container, SWT.BORDER); + list = listViewer.getList(); + final GridData gd_list = new GridData(SWT.LEFT, SWT.FILL, false, true); + gd_list.widthHint = 162; + list.setLayoutData(gd_list); + + listViewer.setContentProvider(new ArrayContentProvider()); + listViewer.setLabelProvider(new LabelProvider() { + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + if (element instanceof ICdmDataSource) { + return ((ICdmDataSource) element).getName(); + } + return super.getText(element); + } + }); +// list.addListener(SWT. .PaintItem, new Listener() { +// @Override +// public void handleEvent(Event event) { +// Object data = event.item.getData(); +// if (!(data instanceof ICdmDataSource)) { +// Font italics = TaxEditorPlugin.getDefault().getFont +// (ITaxEditorConstants.MENU_ITEM_ITALICS_FONT); +// ((Control) event.item).setFont(italics); +// } +// } +// }); + + java.util.List dataSources = + TaxEditorPlugin.getDefault().getDataSources(); + + listViewer.setInput(dataSources); + listViewer.add("<< Add data source >>"); + + listViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + Object selection = + ((IStructuredSelection) event.getSelection()). + getFirstElement(); + if (selection instanceof ICdmDataSource) { + createExistingDatasource((ICdmDataSource) selection); + } else { +// newDataSource(CdmDataSource.); + } + } + }); + + + // + return container; + } + + private void populateComboBoxItems() { + // TODO: replace w cdmApp.getDatabaseService().getDatabaseEnum(); + for (DatabaseTypeEnum type : DatabaseTypeEnum.getAllTypes()) { + datasourceTypesCombo.add(type.getName()); + } + } + + /** + * Create contents of the button bar + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, + true); + createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } + + /** + * Return the initial size of the dialog + */ + @Override + protected Point getInitialSize() { + return new Point(500, 375); + } + + private void createExistingDatasource(ICdmDataSource dataSource) { + composite = new Composite(container, SWT.NONE); + final GridData gd_composite = new GridData(SWT.FILL, SWT.TOP, true, true); + composite.setLayoutData(gd_composite); + final GridLayout gridLayout_1 = new GridLayout(); + gridLayout_1.numColumns = 2; + composite.setLayout(gridLayout_1); + + final Label datasourceNameLabel = new Label(composite, SWT.NONE); + datasourceNameLabel.setText("Datasource Name:"); + + text = new Text(composite, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label databaseTypeLabel = new Label(composite, SWT.NONE); + databaseTypeLabel.setText("Database Type:"); + + datasourceTypesCombo = new CCombo(composite, SWT.BORDER); + final GridData gd_list_1 = new GridData(SWT.FILL, SWT.CENTER, false, false); + datasourceTypesCombo.setLayoutData(gd_list_1); + populateComboBoxItems(); + +// BeanDefinition bean = dataSource.getDatasourceBean(); + + // Redraw dialog container + container.layout(); + } + + private void createMySqlForm(ICdmDataSource dataSource) { + final Group authenticationGroup = new Group(composite, SWT.NONE); + authenticationGroup.setText("Authentication"); + authenticationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + final GridLayout gridLayout_2 = new GridLayout(); + gridLayout_2.numColumns = 2; + authenticationGroup.setLayout(gridLayout_2); + + final Label loginNameLabel = new Label(authenticationGroup, SWT.NONE); + loginNameLabel.setText("Login Name:"); + + text_3 = new Text(authenticationGroup, SWT.BORDER); + text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label passwordLabel = new Label(authenticationGroup, SWT.NONE); + passwordLabel.setText("Password:"); + + text_2 = new Text(authenticationGroup, SWT.BORDER); + text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label savePasswordLabel = new Label(authenticationGroup, SWT.NONE); + savePasswordLabel.setText("Save password:"); + + final Button button = new Button(authenticationGroup, SWT.CHECK); + + final Group locationGroup = new Group(composite, SWT.NONE); + locationGroup.setText("Location"); + final GridData gd_locationGroup = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1); + locationGroup.setLayoutData(gd_locationGroup); + final GridLayout gridLayout_3 = new GridLayout(); + gridLayout_3.numColumns = 2; + locationGroup.setLayout(gridLayout_3); + + final Label hostLabel = new Label(locationGroup, SWT.NONE); + hostLabel.setText("Host:"); + + text_4 = new Text(locationGroup, SWT.BORDER); + text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label portLabel = new Label(locationGroup, SWT.NONE); + portLabel.setText("Port <3306>:"); + + text_5 = new Text(locationGroup, SWT.BORDER); + text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label databaseLabel = new Label(locationGroup, SWT.NONE); + databaseLabel.setText("Database:"); + + text_6 = new Text(locationGroup, SWT.BORDER); + text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + new Label(composite, SWT.NONE); + + final Button saveButton = new Button(composite, SWT.NONE); + final GridData gd_saveButton = new GridData(SWT.RIGHT, SWT.CENTER, false, false); + gd_saveButton.widthHint = 76; + saveButton.setLayoutData(gd_saveButton); + saveButton.setText("Save"); + } +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CopyOfCdmDataSourceDialog.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CopyOfCdmDataSourceDialog.java new file mode 100644 index 000000000..185a222bc --- /dev/null +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/CopyOfCdmDataSourceDialog.java @@ -0,0 +1,254 @@ +package eu.etaxonomy.taxeditor.datasource; + +import java.util.ArrayList; + +import org.apache.log4j.Logger; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.views.properties.PropertySheet; + +import eu.etaxonomy.cdm.database.CdmDataSource; +import eu.etaxonomy.cdm.database.DatabaseTypeEnum; +import eu.etaxonomy.cdm.database.ICdmDataSource; +import eu.etaxonomy.taxeditor.ITaxEditorConstants; +import eu.etaxonomy.taxeditor.TaxEditorPlugin; + +public class CopyOfCdmDataSourceDialog extends Dialog { + private List list; + private List list_1; + private Text text_6; + private Text text_5; + private Text text_4; + private Text text_2; + private Text text_3; + private Text text; + private static final Logger logger = Logger + .getLogger(CopyOfCdmDataSourceDialog.class); + private CCombo datasourceTypesCombo; + private Composite composite; + private Composite container; + + /** + * Create the dialog + * @param parentShell + */ + public CopyOfCdmDataSourceDialog(Shell parentShell) { + super(parentShell); + } + + /** + * Create contents of the dialog + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + container = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + container.setLayout(gridLayout); + + final ListViewer listViewer = new ListViewer(container, SWT.BORDER); + list = listViewer.getList(); + final GridData gd_list = new GridData(SWT.LEFT, SWT.FILL, false, true); + gd_list.widthHint = 162; + list.setLayoutData(gd_list); + + listViewer.setContentProvider(new ArrayContentProvider()); + listViewer.setLabelProvider(new LabelProvider() { + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + if (element instanceof ICdmDataSource) { + return ((ICdmDataSource) element).getName(); + } + return super.getText(element); + } + }); +// list.addListener(SWT. .PaintItem, new Listener() { +// @Override +// public void handleEvent(Event event) { +// Object data = event.item.getData(); +// if (!(data instanceof ICdmDataSource)) { +// Font italics = TaxEditorPlugin.getDefault().getFont +// (ITaxEditorConstants.MENU_ITEM_ITALICS_FONT); +// ((Control) event.item).setFont(italics); +// } +// } +// }); + + ArrayList dataSources = new ArrayList(); + dataSources.add(CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "")); + dataSources.add(CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_editor_test1", "edit", "wp5")); + listViewer.setInput(dataSources); + listViewer.add("<< Add data source >>"); + + listViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + Object selection = + ((IStructuredSelection) event.getSelection()). + getFirstElement(); + if (selection instanceof ICdmDataSource) { + createExistingDatasource((ICdmDataSource) selection); + } else { +// newDataSource(CdmDataSource.); + } + } + }); + +// composite = new Composite(container, SWT.NONE); +// final GridData gd_composite = new GridData(SWT.FILL, SWT.TOP, true, true); +// composite.setLayoutData(gd_composite); +// final GridLayout gridLayout_1 = new GridLayout(); +// gridLayout_1.numColumns = 2; +// composite.setLayout(gridLayout_1); +// +// final Label datasourceNameLabel = new Label(composite, SWT.NONE); +// datasourceNameLabel.setText("Datasource Name:"); +// +// text = new Text(composite, SWT.BORDER); +// text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); +// +// final Label databaseTypeLabel = new Label(composite, SWT.NONE); +// databaseTypeLabel.setText("Database Type:"); +// +// datasourceTypesCombo = new CCombo(composite, SWT.BORDER); +// final GridData gd_list_1 = new GridData(SWT.FILL, SWT.CENTER, false, false); +// datasourceTypesCombo.setLayoutData(gd_list_1); +// populateComboBoxItems(); + + // + return container; + } + + private void populateComboBoxItems() { + for (DatabaseTypeEnum type : DatabaseTypeEnum.getAllTypes()) { + datasourceTypesCombo.add(type.getName()); + } + } + + /** + * Create contents of the button bar + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, + true); + createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } + + /** + * Return the initial size of the dialog + */ + @Override + protected Point getInitialSize() { + return new Point(500, 375); + } + + private void createExistingDatasource(ICdmDataSource dataSource) { + composite = new Composite(container, SWT.NONE); + final GridData gd_composite = new GridData(SWT.FILL, SWT.TOP, true, true); + composite.setLayoutData(gd_composite); + final GridLayout gridLayout_1 = new GridLayout(); + gridLayout_1.numColumns = 2; + composite.setLayout(gridLayout_1); + + final Label datasourceNameLabel = new Label(composite, SWT.NONE); + datasourceNameLabel.setText("Datasource Name:"); + + text = new Text(composite, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label databaseTypeLabel = new Label(composite, SWT.NONE); + databaseTypeLabel.setText("Database Type:"); + + datasourceTypesCombo = new CCombo(composite, SWT.BORDER); + final GridData gd_list_1 = new GridData(SWT.FILL, SWT.CENTER, false, false); + datasourceTypesCombo.setLayoutData(gd_list_1); + populateComboBoxItems(); + } + + private void createMySqlForm(ICdmDataSource dataSource) { + final Group authenticationGroup = new Group(composite, SWT.NONE); + authenticationGroup.setText("Authentication"); + authenticationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + final GridLayout gridLayout_2 = new GridLayout(); + gridLayout_2.numColumns = 2; + authenticationGroup.setLayout(gridLayout_2); + + final Label loginNameLabel = new Label(authenticationGroup, SWT.NONE); + loginNameLabel.setText("Login Name:"); + + text_3 = new Text(authenticationGroup, SWT.BORDER); + text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label passwordLabel = new Label(authenticationGroup, SWT.NONE); + passwordLabel.setText("Password:"); + + text_2 = new Text(authenticationGroup, SWT.BORDER); + text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label savePasswordLabel = new Label(authenticationGroup, SWT.NONE); + savePasswordLabel.setText("Save password:"); + + final Button button = new Button(authenticationGroup, SWT.CHECK); + + final Group locationGroup = new Group(composite, SWT.NONE); + locationGroup.setText("Location"); + final GridData gd_locationGroup = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1); + locationGroup.setLayoutData(gd_locationGroup); + final GridLayout gridLayout_3 = new GridLayout(); + gridLayout_3.numColumns = 2; + locationGroup.setLayout(gridLayout_3); + + final Label hostLabel = new Label(locationGroup, SWT.NONE); + hostLabel.setText("Host:"); + + text_4 = new Text(locationGroup, SWT.BORDER); + text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label portLabel = new Label(locationGroup, SWT.NONE); + portLabel.setText("Port <3306>:"); + + text_5 = new Text(locationGroup, SWT.BORDER); + text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + final Label databaseLabel = new Label(locationGroup, SWT.NONE); + databaseLabel.setText("Database:"); + + text_6 = new Text(locationGroup, SWT.BORDER); + text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + new Label(composite, SWT.NONE); + + final Button saveButton = new Button(composite, SWT.NONE); + final GridData gd_saveButton = new GridData(SWT.RIGHT, SWT.CENTER, false, false); + gd_saveButton.widthHint = 76; + saveButton.setLayoutData(gd_saveButton); + saveButton.setText("Save"); + } +} diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/RegisterDatabaseDialog.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/RegisterDatabaseDialog.java similarity index 96% rename from eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/RegisterDatabaseDialog.java rename to eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/RegisterDatabaseDialog.java index d04033ee0..2773e6043 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/RegisterDatabaseDialog.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/datasource/RegisterDatabaseDialog.java @@ -1,4 +1,4 @@ -package eu.etaxonomy.taxeditor.editor; +package eu.etaxonomy.taxeditor.datasource; import org.apache.log4j.Logger; import org.eclipse.jface.dialogs.IDialogConstants; diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditorView.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditorView.java index db77cc616..b75ac82f8 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditorView.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditorView.java @@ -189,13 +189,8 @@ public abstract class AbstractTaxonEditorView extends EditorPart implements @SuppressWarnings("unchecked") public Object getAdapter(Class type) { if (type == IPropertySheetPage.class) { - PropertySheetPage page = new PropertySheetPage() { - public void refresh() { - logger.warn("Refreshing property sheet page"); - super.refresh(); - } - }; - + + PropertySheetPage page = new PropertySheetPage(); CustomSortPropertySheetEntry entry = new CustomSortPropertySheetEntry(); page.setRootEntry(entry); page.refresh(); diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/EditorGroupedComposite.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/EditorGroupedComposite.java index 4eb30fdb6..58769bdc6 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/EditorGroupedComposite.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/EditorGroupedComposite.java @@ -126,6 +126,14 @@ abstract public class EditorGroupedComposite extends GroupedComposite { this.textViewer = textViewer; } + public void setText(String text) { + Assert.isNotNull(getTextViewer(), + "Cannot set text for a TextViewer that has not yet been initialized."); + Assert.isNotNull(getTextViewer().getDocument(), + "Cannot set text for a TextViewer whose Document has not yet been initialized."); + getTextViewer().getDocument().set(text); + } + /** * @param icon */ diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java index 8784582da..8819ed9e8 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java @@ -301,8 +301,7 @@ public class NameComposite extends EditorGroupedComposite { // CdmUtil.parseFullName(nonViralName, text, null, true); // Changed makeEmpty from true -> false -// CdmUtil.parseFullReference(nonViralName, text, null, true); - CdmUtil.parseFullReference(nonViralName, text, null, false); + CdmUtil.parseFullReference(nonViralName, text, null, true); nameViewer.setShowError(nonViralName.getHasProblem()); } diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java index 0408425e3..7687bab87 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java @@ -219,7 +219,8 @@ public class CdmUtil { */ public static String getDisplayName(TaxonNameBase name) { if (name != null) { - return name.getTitleCache(); +// return name.getTitleCache(); + return name.getFullTitleCache(); } return ""; } @@ -267,6 +268,7 @@ public class CdmUtil { */ public static void parseFullReference(NonViralName nameToBeFilled, String fullReference, Rank rank, boolean makeEmpty) { getNonViralNameParser().parseFullReference(nameToBeFilled, fullReference, rank, makeEmpty); + nameToBeFilled.setFullTitleCache(nameToBeFilled.generateFullTitle(), false); } /** diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java index 3ac4670c1..2b64351d2 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java @@ -9,16 +9,24 @@ package eu.etaxonomy.taxeditor.navigation; +import java.util.List; + import org.apache.log4j.Logger; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.ManagedForm; import org.eclipse.ui.forms.events.HyperlinkAdapter; @@ -30,9 +38,12 @@ import org.eclipse.ui.part.ViewPart; import com.swtdesigner.ResourceManager; import com.swtdesigner.SWTResourceManager; +import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.taxeditor.ITaxEditorConstants; import eu.etaxonomy.taxeditor.TaxEditorPlugin; +import eu.etaxonomy.taxeditor.UiUtil; import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction; +import eu.etaxonomy.taxeditor.datasource.CdmDataSourceDialog; /** * The left navigation pane. @@ -52,6 +63,8 @@ public class TaxonomicTreeView extends ViewPart { private TaxonomicTreeViewer treeViewer; private IManagedForm linkForm; + + private Menu dataSourceMenu; /** * Create contents of the view part @@ -82,37 +95,17 @@ public class TaxonomicTreeView extends ViewPart { lblDataSourceTitle.setAlignment(SWT.CENTER); lblDataSourceTitle.setText(" Local"); - final Label lblDbImg = new Label(dbComposite, SWT.NONE); - lblDbImg.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - lblDbImg.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); - lblDbImg.setImage(ResourceManager.getPluginImage(TaxEditorPlugin.getDefault(), "icons/db.gif")); - lblDbImg.setImage(TaxEditorPlugin.getDefault().getImageRegistry().get(ITaxEditorConstants.DB_ICON)); - -// final Menu menu = new Menu(lblDbImg); -// lblDbImg.setMenu(menu); -// -// final MenuItem checkboxMenuItem = new MenuItem(menu, SWT.CHECK); -// checkboxMenuItem.setSelection(true); -// checkboxMenuItem.setText("Euro+Med (mssql://128.14.101.12:80/europlusmed)"); -// -// final MenuItem checkboxMenuItem_1 = new MenuItem(menu, SWT.CHECK); -// checkboxMenuItem_1.setText("WP6 (mssql://128.14.101.13:80/wp6)"); -// -// final MenuItem palmWebora1922299480pwMenuItem = new MenuItem(menu, SWT.NONE); -// palmWebora1922299480pwMenuItem.setText("Palm Web (ora://192.22.99.4:80/pw)"); -// -// new MenuItem(menu, SWT.SEPARATOR); -// -// final MenuItem newDataSourceMenuItem = new MenuItem(menu, SWT.NONE); -// newDataSourceMenuItem.setText("New data source ..."); -// newDataSourceMenuItem.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent event) { -// Shell shell = UiUtil.getShell(); -// Dialog dialog = new RegisterDatabaseDialog(shell); -//// Taxon destinationTaxon = dialog.open(); -// dialog.open(); -// } -// }); + final Label lblDatasourceMenu = new Label(dbComposite, SWT.NONE); + lblDatasourceMenu.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + lblDatasourceMenu.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + lblDatasourceMenu.setImage(ResourceManager.getPluginImage(TaxEditorPlugin.getDefault(), "icons/db.gif")); + lblDatasourceMenu.setImage(TaxEditorPlugin.getDefault().getImageRegistry().get(ITaxEditorConstants.DB_ICON)); + + dataSourceMenu = new Menu(lblDatasourceMenu); + lblDatasourceMenu.setMenu(dataSourceMenu); + + createDataSourceMenu(); + // final Label lblDataSource = new Label(dbComposite, SWT.NONE); final GridData gd_lblDataSource = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1); @@ -163,6 +156,42 @@ public class TaxonomicTreeView extends ViewPart { // TaxEditorPlugin.getDefault().setTaxonomicTree(this); } + private void createDataSourceMenu() { + + // Get current datasource and list of all data sources + ICdmDataSource sessionDataSource = TaxEditorPlugin.getDefault() + .getCdmDataSource(); + List dataSources = + TaxEditorPlugin.getDefault().getDataSources(); + + // Create menu items, putting a check next to the current one + for (ICdmDataSource dataSource : dataSources) { + MenuItem item = new MenuItem(dataSourceMenu, SWT.CHECK); + + if (dataSource.equals(sessionDataSource)) { + item.setSelection(true); + } + + String text = dataSource.getName(); + if (dataSource.getDatabase() != null) { + text += " (" + dataSource.getDatabase() + ")"; + } + item.setText(text); + } + + new MenuItem(dataSourceMenu, SWT.SEPARATOR); + + final MenuItem newDataSourceMenuItem = new MenuItem(dataSourceMenu, SWT.NONE); + newDataSourceMenuItem.setText("Edit data sources ..."); + newDataSourceMenuItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + Shell shell = UiUtil.getShell(); + Dialog dialog = new CdmDataSourceDialog(shell); + dialog.open(); + } + }); + } + public TaxonomicTreeViewer createTreeViewer() { // Dispose link to new taxon as necessary diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java index e817777fd..8da74a124 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java @@ -345,7 +345,8 @@ public class NonViralNamePropertySource implements IPropertySource { // If the name has not been parsed, only show the title cache // if (name.getHasProblem()) { if (name.getRank() == null) { - return subEmptyForNull(name.getTitleCache()); +// return subEmptyForNull(name.getTitleCache()); + return subEmptyForNull(name.getFullTitleCache()); } else { return new NonViralNamePropertySource(name, P_ID_TITLECACHE, getNameFields()); } @@ -525,6 +526,7 @@ public class NonViralNamePropertySource implements IPropertySource { } if (id.equals(P_ID_SPECIESEP)) { name.setSpecificEpithet((String) value); + name.setAppendedPhrase("joemama"); } if (id.equals(P_ID_INFRASPECIFICEP)) { name.setInfraSpecificEpithet((String) value); @@ -579,6 +581,8 @@ public class NonViralNamePropertySource implements IPropertySource { if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) { // TODO decide if this is editable at all, and if so, how to implement } + boolean test = false; + if (test) test = true; } /** @@ -590,7 +594,8 @@ public class NonViralNamePropertySource implements IPropertySource { @Override public String toString() { if (parentid.equals(P_ID_TITLECACHE)) - return name.getTitleCache(); +// return name.getTitleCache(); + return name.getFullTitleCache(); return super.toString(); } -- 2.34.1