2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
11 import java
.util
.UUID
;
13 import org
.eclipse
.jface
.dialogs
.InputDialog
;
14 import org
.eclipse
.jface
.window
.Window
;
15 import org
.eclipse
.swt
.events
.SelectionAdapter
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.events
.SelectionListener
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IWorkingSetService
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.description
.WorkingSet
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 public class WorkingSetSelectionDialog
extends
34 AbstractFilteredCdmResourceSelectionDialog
<WorkingSet
> {
36 public static WorkingSet
select(Shell shell
, WorkingSet workingSet
){
37 WorkingSetSelectionDialog dialog
= new WorkingSetSelectionDialog(shell
,
38 "Choose working set", false, WorkingSetSelectionDialog
.class.getCanonicalName(), workingSet
);
39 return getSelectionFromDialog(dialog
);
43 * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
45 protected WorkingSetSelectionDialog(Shell shell
, String title
,
46 boolean multi
, String settings
, WorkingSet cdmObject
) {
47 super(shell
, title
, multi
, settings
, cdmObject
);
52 protected WorkingSet
getPersistentObject(UUID uuid
) {
53 Object object
= CdmStore
.getService(IWorkingSetService
.class).load(uuid
);
55 WorkingSet workingSet
= (WorkingSet
) HibernateProxyHelper
.deproxy(object
);
57 if(workingSet
!= null){
60 MessagingUtils
.error(this.getClass(), "Selected element is not a working set", null);
66 protected void callService(String pattern
) {
67 model
= CdmStore
.getService(IWorkingSetService
.class).getUuidAndTitleCache(limitOfInitialElements
, pattern
);
71 protected String
getTitle(WorkingSet cdmObject
) {
73 return cdmObject
.getLabel();
75 return super.getTitle(cdmObject
);
80 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
85 protected SelectionListener
getNewWizardButtonSelectionListener(){
86 return new SelectionAdapter() {
89 public void widgetSelected(SelectionEvent e
) {
90 Object source
= e
.getSource();
91 if (source
instanceof Button
){
92 Button sourceButton
= (Button
) source
;
94 InputDialog dialog
= new InputDialog(getShell(), "Working set label", "Enter label for working set", null, null);
95 if (dialog
.open() == Window
.OK
) {
96 // User clicked OK; update the label with the input
97 WorkingSet workingSet
= WorkingSet
.NewInstance();
98 CdmStore
.getService(IWorkingSetService
.class).merge(workingSet
,true);
99 workingSet
.setLabel(dialog
.getValue());
100 workingSet
.setTitleCache(dialog
.getValue(), true);
102 setPattern(workingSet
);
110 protected String
[] getNewWizardText() {
111 return new String
[]{"Working set "};