import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
-import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;
import eu.etaxonomy.taxeditor.model.Resources;
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
* @author n.hoffmann
public class SearchBar extends WorkbenchWindowControlContribution{
private static final Logger logger = Logger.getLogger(SearchBar.class);
private Text text_search;
- private Button button_search;
private String srv;
private String defaultText = "Use \"*\" for wildcard searching";
- private Button button_configure;
+
+ final private ConfigurationSelectionListener configurationListener = new ConfigurationSelectionListener();
@Override
protected Control createControl(Composite parent) {
//parent.setLayout(new FillLayout());
Composite composite = new Composite(parent, SWT.NONE);
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 3;
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- composite.setLayout(gridLayout);
+
+ final RowLayout layout = new RowLayout();
+ layout.wrap = false;
+ layout.pack = true;
+ layout.justify = true;
+ layout.type = SWT.HORIZONTAL;
+ layout.marginLeft = 0;
+ layout.marginTop = 0;
+ layout.marginRight = 0;
+ layout.marginBottom = 0;
+ layout.spacing = 0;
+ composite.setLayout(layout);
+
// FIXME we have this here for debugging purposes, remove color once the layout of the search bar is correct
composite.setBackground(Resources.getColor(Resources.SEARCH_VIEW_FOREGROUND));
- text_search = new Text(composite, SWT.SEARCH);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
-
- text_search.setLayoutData(gridData);
+ // TODO for some reason the text_search composite has a margin when either SWT.BORDER or SWT.SEARCH
+ // is applied. I am not sure how to get rid of this.
+ text_search = new Text(composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
text_search.setForeground(Resources.getColor(Resources.SEARCH_VIEW_FOREGROUND));
text_search.setText(defaultText);
}
}
});
- text_search.addKeyListener(new KeyAdapter() {
- public void keyReleased(KeyEvent e) {
- int key = e.keyCode;
- if (key == SWT.CR) {
- openSearchResultsView(text_search);
- } else {
- setSearchButtonEnabled();
- }
- }
- });
+
- button_configure = new Button(composite, SWT.DROP_DOWN);
- button_configure.setImage(ImageResources.getImage(ImageResources.MOVE_ICON));
+ final ToolBar toolBar = new ToolBar(composite, SWT.NULL);
- button_search = new Button(composite, SWT.PUSH);
- button_search.setText("Search");
- button_search.setEnabled(false);
- button_search.addMouseListener(new MouseAdapter() {
-
- // Populate search results resultsTable after clicking button
- public void mouseUp(MouseEvent e) {
- openSearchResultsView(text_search);
- }
- });
- return composite;
- }
+ ToolItem toolItem = new ToolItem(toolBar, SWT.DROP_DOWN);
+ toolItem.setText("Search");
+
+ DropdownSelectionListener dropdownListener = new DropdownSelectionListener(toolItem);
+
+ dropdownListener.add(SearchOption.TAXON);
+ dropdownListener.add(SearchOption.SYNONYM);
+ dropdownListener.add(SearchOption.NAME);
+ dropdownListener.add(SearchOption.COMMON_NAME);
+
+ toolItem.addSelectionListener(dropdownListener);
- protected void setSearchButtonEnabled() {
- if (text_search.getText().length() == 0) {
- button_search.setEnabled(false);
- } else {
- button_search.setEnabled(true);
- }
+
+ return composite;
}
-
- private void openSearchResultsView(Text searchText) {
- if(searchText.getText().length() > 0){
+
+ private void openSearchResultsView() {
+ if(text_search.getText().trim().length() > 0){
+
+ ITaxonServiceConfigurator configurator = configurationListener.getConfigurator();
+ configurator.setSearchString(text_search.getText().trim());
+
srv += "1";
logger.info("Opening search results window " + srv);
try {
IViewPart resultsView = TaxeditorNavigationPlugin.getDefault().getWorkbench()
.getActiveWorkbenchWindow().getActivePage().showView(SearchResultView.ID,
srv, IWorkbenchPage.VIEW_ACTIVATE);
- ((SearchResultView) resultsView).performSearch(searchText.getText());
+ ((SearchResultView) resultsView).performSearch(configurator);
} catch (PartInitException e) {
logger.error("Error opening search result.", e);
}
}
}
+
+ class DropdownSelectionListener extends SelectionAdapter {
+
+ private Menu menu;
+
+ public DropdownSelectionListener(ToolItem dropdown) {
+ menu = new Menu(dropdown.getParent().getShell());
+ }
+
+ public void add(SearchOption option) {
+ MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
+ menuItem.setData(option);
+ menuItem.setText(option.getLabel());
+ menuItem.setSelection(option.getPreference());
+ menuItem.addSelectionListener(configurationListener);
+ }
+
+ public void widgetSelected(SelectionEvent event) {
+ if (event.detail == SWT.ARROW) {
+ ToolItem item = (ToolItem) event.widget;
+ Rectangle rect = item.getBounds();
+ Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
+ menu.setLocation(pt.x, pt.y + rect.height);
+ menu.setVisible(true);
+ } else {
+ openSearchResultsView();
+ }
+ }
+ }
+
+ class ConfigurationSelectionListener extends SelectionAdapter{
+
+ ITaxonServiceConfigurator configurator;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ logger.warn("configuration menu clicked");
+ SearchOption option = (SearchOption) e.widget.getData();
+
+ if(option == SearchOption.TAXON){
+ getConfigurator().setDoTaxa(configurator.isDoTaxa() ? false : true);
+ }
+
+ if(option == SearchOption.SYNONYM){
+ getConfigurator().setDoSynonyms(configurator.isDoSynonyms() ? false : true);
+ }
+
+ if(option == SearchOption.NAME){
+ getConfigurator().setDoNamesWithoutTaxa(configurator.isDoNamesWithoutTaxa() ? false : true);
+ }
+
+ if(option == SearchOption.COMMON_NAME){
+ getConfigurator().setDoTaxaByCommonNames(configurator.isDoTaxaByCommonNames() ? false : true);
+ }
+ saveConfigurator();
+ }
+
+ public ITaxonServiceConfigurator getConfigurator(){
+ if(configurator == null){
+ configurator = PreferencesUtil.getSearchConfigurator();
+ }
+ return configurator;
+ }
+
+ private void saveConfigurator(){
+ PreferencesUtil.setSearchConfigurator(configurator);
+ this.configurator = PreferencesUtil.getSearchConfigurator();
+ }
+ }
+
+ enum SearchOption {
+ TAXON("Taxa"),
+ SYNONYM("Synonyms"),
+ NAME("Names (without taxa)"),
+ COMMON_NAME("Common Names");
+
+ private String label;
+
+ private SearchOption(String label){
+ this.label = label;
+ }
+
+ public String getLabel(){
+ return label;
+ }
+
+ public boolean getPreference(){
+ switch(this){
+ case TAXON:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
+ case SYNONYM:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
+ case NAME:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_NAMES);
+ case COMMON_NAME:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
+ }
+
+ return true;
+ }
+
+
+
+ }
}
\r
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;\r
+import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;\r
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;\r
private String queryString;\r
\r
private ConversationHolder conversation;\r
+\r
+ private ITaxonServiceConfigurator configurator;\r
\r
\r
/* (non-Javadoc)\r
control.setMenu(menu); \r
}\r
\r
+ @Deprecated\r
protected void performSearch(String queryString) {\r
List searchResult = CdmStore.searchTaxaByName(queryString);\r
\r
resultViewer.setInput(searchResult); \r
setPartName("Search: '" + queryString + "'");\r
}\r
+ \r
+ protected void performSearch(ITaxonServiceConfigurator configurator) {\r
+ List searchResult = CdmStore.findNames(configurator);\r
+ \r
+ resultViewer.setInput(searchResult); \r
+ setPartName("Search: '" + configurator.getSearchString() + "'");\r
+\r
+ this.configurator = configurator;\r
+ }\r
\r
/* (non-Javadoc)\r
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
private static Text text_password;
private static Text text_username;
+ private String title;
+
/**
* @param parentShell
*/
public LoginDialog(Shell parentShell) {
super(parentShell);
+ title = "Login";
}
passwordLabel.setText("Password");
// Textfield for the password
- text_password = new Text(composite, SWT.BORDER);
- text_password.setEchoChar('*');
+ text_password = new Text(composite, SWT.PASSWORD | SWT.BORDER);
text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
return composite;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ if (title != null) {
+ shell.setText(title);
+ }
+ }
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
package eu.etaxonomy.taxeditor.preference;\r
\r
import java.util.ArrayList;\r
-import java.util.HashSet;\r
import java.util.List;\r
import java.util.Set;\r
\r
import org.apache.log4j.Logger;\r
import org.eclipse.jface.preference.IPreferenceStore;\r
\r
+import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;\r
+import eu.etaxonomy.cdm.api.service.config.impl.TaxonServiceConfiguratorImpl;\r
import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
import eu.etaxonomy.cdm.model.common.TermBase;\r
import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;\r
import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
import eu.etaxonomy.taxeditor.model.Resources;\r
import eu.etaxonomy.taxeditor.store.VocabularyStore;\r
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;\r
private static final Logger logger = Logger\r
.getLogger(PreferencesUtil.class);\r
\r
+ public static final String TAXON_SERVICE_CONFIGURATOR_TAXA = "TAXON_SERVICE_CONFIGURATOR_TAXA";\r
+ public static final String TAXON_SERVICE_CONFIGURATOR_SYNONYMS = "TAXON_SERVICE_CONFIGURATOR_SYNONYMS";\r
+ public static final String TAXON_SERVICE_CONFIGURATOR_NAMES = "TAXON_SERVICE_CONFIGURATOR_NAMES";\r
+ public static final String TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES = "TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES";\r
+ \r
/**\r
* \r
* @return\r
. concat(".")\r
. concat(term.getUuid().toString());\r
}\r
+\r
+ /**\r
+ * Retrieves search preferences from the preference store\r
+ * \r
+ * @return an <code>ITaxonServiceConfigurator</code> to pass to search methods\r
+ */\r
+ public static ITaxonServiceConfigurator getSearchConfigurator() {\r
+ ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl.NewInstance();\r
+ // check for existence of at least one preference variable\r
+ if(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_TAXA)){\r
+ // preferences exist\r
+ configurator.setDoTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_TAXA));\r
+ configurator.setDoSynonyms(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_SYNONYMS));\r
+ configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_NAMES));\r
+ configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)); \r
+ }else{\r
+ // create new preferences setting everything to true\r
+ configurator.setDoTaxa(true);\r
+ configurator.setDoSynonyms(true);\r
+ configurator.setDoNamesWithoutTaxa(true);\r
+ configurator.setDoTaxaByCommonNames(true);\r
+ setSearchConfigurator(configurator);\r
+ }\r
+ \r
+ // DEFAULT VALUES \r
+ // match mode default only\r
+ configurator.setMatchMode(MatchMode.BEGINNING);\r
+ // i don't know what happens to sec at the moment\r
+ configurator.setSec(null);\r
+ // we set page number and size here as this should always be unlimited\r
+ configurator.setPageNumber(0);\r
+ // TODO currently limit results to 1000\r
+ configurator.setPageSize(1000);\r
+ \r
+ return configurator;\r
+ }\r
+ \r
+ /**\r
+ * Store search preferences\r
+ * \r
+ * @param configurator\r
+ */\r
+ public static void setSearchConfigurator(ITaxonServiceConfigurator configurator){\r
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, configurator.isDoTaxa());\r
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, configurator.isDoSynonyms());\r
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, configurator.isDoNamesWithoutTaxa());\r
+ getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, configurator.isDoTaxaByCommonNames());\r
+ }\r
}\r
return resultSet;
}
+ @Deprecated
private List<IdentifiableEntity> findTaxaByName(String queryString, boolean restrictToTaxonObjs) {
ITaxonServiceConfigurator configurator = new TaxonServiceConfiguratorImpl();
return result;
}
+
+
+ private List<IdentifiableEntity> findTaxaByName(ITaxonServiceConfigurator configurator){
+
+ List<IdentifiableEntity> result = getTaxonService().findTaxaAndNames(configurator).getRecords();
+
+ return result;
+ }
+
+ public static List<IdentifiableEntity> findNames(ITaxonServiceConfigurator configurator){
+ return getDefault().findTaxaByName(configurator);
+ }
+
+
+
public static List<IdentifiableEntity> searchTaxaByName(String queryString){
return getDefault().findTaxaByName(queryString, false);
}
fillLayout.type = SWT.VERTICAL;
parent.setLayout(fillLayout);
- Composite composite = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- composite.setLayout(layout);
+ listViewer = new ListViewer(parent, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.FULL_SELECTION);
-
- listViewer = new ListViewer(composite);
- Control control = listViewer.getControl();
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- // register context menu
MenuManager menuMgr = new MenuManager();
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
getSite().registerContextMenu(menuMgr, listViewer);
+ Control control = listViewer.getControl();
Menu menu = menuMgr.createContextMenu(control);
control.setMenu(menu);
package eu.etaxonomy.taxeditor.user.wizard;
import org.apache.log4j.Logger;
+import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
* @version 1.0
*/
public class UserWizardPage extends WizardPage implements ModifyListener{
+
+ public static final String NAME = "USER_WIZARD_PAGE";
+
+
private Composite composite;
private Text text_username;
private Text text_oldPassword;
private Text text_personLastName;
private Text text_userEmail;
+ private IInputValidator uniqueUserNameValidator;
+ private IInputValidator passwordRepetitionEqualityValidator;
+
/**
* @param pageName
*/
protected UserWizardPage(User user) {
- super("USER_WIZARD_PAGE");
+ super(NAME);
this.user = user;
}else{
setTitle("Edit existing user");
setDescription("Edit information for the selected user.");
-
- }
+ }
+
+ uniqueUserNameValidator = new UniqueUserNameValidator();
+ passwordRepetitionEqualityValidator = new PasswordRepetitionEqualityValidator();
}
private static final Logger logger = Logger.getLogger(UserWizardPage.class);
setControl(composite);
+ setPageComplete(false);
+
init();
}
private void createPasswordFieldsEdit(Composite parent){
CLabel label_oldPassword = new CLabel(parent, SWT.NULL);
label_oldPassword.setText("Old Password");
- text_oldPassword = new Text(parent, SWT.BORDER);
- text_oldPassword.setEchoChar('*');
+ text_oldPassword = new Text(parent, SWT.PASSWORD | SWT.BORDER);
text_oldPassword.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
text_oldPassword.addModifyListener(this);
CLabel label_password = new CLabel(parent, SWT.NULL);
label_password.setText("Password");
- text_password = new Text(parent, SWT.BORDER);
- text_password.setEchoChar('*');
+ text_password = new Text(parent, SWT.PASSWORD | SWT.BORDER);
text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
text_password.addModifyListener(this);
public User getUser() {
return user;
}
+
+ private class UniqueUserNameValidator implements IInputValidator{
+
+ private static final String MESSAGE = "Username already exists";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+ */
+ public String isValid(String newText) {
+ // query for username
+ if( CdmStore.getUserService().loadUserByUsername(newText) != null){
+ return MESSAGE;
+ }
+
+ return null;
+ }
+ }
+
+ private class PasswordRepetitionEqualityValidator implements IInputValidator{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+ */
+ public String isValid(String newText) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
}