2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.jface
.dialogs
.InputDialog
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Control
;
21 import org
.eclipse
.swt
.widgets
.Event
;
22 import org
.eclipse
.swt
.widgets
.Link
;
23 import org
.eclipse
.swt
.widgets
.Listener
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
28 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
30 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * @created Sep 17, 2010
38 public class FeatureTreeSelectionDialog
extends
39 AbstractFilteredCdmResourceSelectionDialog
<FeatureTree
> {
41 public static FeatureTree
select(Shell shell
, ConversationHolder conversation
, FeatureTree featureTree
) {
42 FeatureTreeSelectionDialog dialog
= new FeatureTreeSelectionDialog(shell
, conversation
,
43 "Choose a feature tree", false, featureTree
);
44 return getSelectionFromDialog(dialog
);
47 protected FeatureTreeSelectionDialog(Shell shell
,
48 ConversationHolder conversation
, String title
, boolean multi
,
49 FeatureTree cdmObject
) {
50 super(shell
, conversation
, title
, multi
, FeatureTreeSelectionDialog
.class.getCanonicalName(), cdmObject
);
55 protected FeatureTree
getPersistentObject(UUID uuid
) {
56 return CdmStore
.getService(IFeatureTreeService
.class).load(uuid
);
61 protected void search() {
62 List
<FeatureTree
> featureTrees
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
65 model
= new ArrayList
<UuidAndTitleCache
<FeatureTree
>>();
68 for(FeatureTree featureTree
: featureTrees
){
69 UuidAndTitleCache
<FeatureTree
> element
= new UuidAndTitleCache
<FeatureTree
>(FeatureTree
.class, featureTree
.getUuid(),featureTree
.getId(), featureTree
.getTitleCache());
76 protected Control
createExtendedContentArea(Composite parent
) {
77 Link link
= new Link(parent
, SWT
.NONE
);
78 link
.setText(getNewWizardLinkText());
79 link
.addListener (SWT
.Selection
, new Listener () {
81 public void handleEvent(Event event
) {
83 InputDialog input
= new InputDialog(getShell(), "New feature tree", "Enter label for new feature tree", null, null);
84 int status
= input
.open();
85 if (status
== IStatus
.OK
) {
86 String label
= input
.getValue();
88 FeatureTree featureTree
= FeatureTree
.NewInstance();
89 featureTree
.setTitleCache(label
, false);
90 CdmStore
.getService(IFeatureTreeService
.class).save(featureTree
);
91 UuidAndTitleCache
<FeatureTree
> uuidAndTitleCache
= new UuidAndTitleCache
<FeatureTree
>(FeatureTree
.class, featureTree
.getUuid(),featureTree
.getId(), featureTree
.getTitleCache());
92 model
.add(uuidAndTitleCache
);
93 setPattern(featureTree
);
103 protected String
getNewWizardLinkText() {
104 return String
.format("Create a new <a>%1s</a>" , "Feature tree ");
110 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {