3987 |
17 Nov 10 |
gregory |
1 |
/* |
3987 |
17 Nov 10 |
gregory |
Copyright (C) 2006 Gregory Vincic |
3987 |
17 Nov 10 |
gregory |
3 |
|
3987 |
17 Nov 10 |
gregory |
This file is part of Proteios. |
3987 |
17 Nov 10 |
gregory |
Available at http://www.proteios.org/ |
3987 |
17 Nov 10 |
gregory |
6 |
|
3987 |
17 Nov 10 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
3987 |
17 Nov 10 |
gregory |
under the terms of the GNU General Public License as published by |
3987 |
17 Nov 10 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
3987 |
17 Nov 10 |
gregory |
(at your option) any later version. |
3987 |
17 Nov 10 |
gregory |
11 |
|
3987 |
17 Nov 10 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
3987 |
17 Nov 10 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
3987 |
17 Nov 10 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3987 |
17 Nov 10 |
gregory |
General Public License for more details. |
3987 |
17 Nov 10 |
gregory |
16 |
|
3987 |
17 Nov 10 |
gregory |
You should have received a copy of the GNU General Public License |
3987 |
17 Nov 10 |
gregory |
along with this program; if not, write to the Free Software |
3987 |
17 Nov 10 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
3987 |
17 Nov 10 |
gregory |
02111-1307, USA. |
3987 |
17 Nov 10 |
gregory |
21 |
*/ |
3987 |
17 Nov 10 |
gregory |
22 |
package greg; |
3987 |
17 Nov 10 |
gregory |
23 |
|
3987 |
17 Nov 10 |
gregory |
24 |
import java.util.ArrayList; |
3987 |
17 Nov 10 |
gregory |
25 |
import java.util.List; |
3987 |
17 Nov 10 |
gregory |
26 |
import org.proteios.ActionLink; |
3987 |
17 Nov 10 |
gregory |
27 |
import org.proteios.Context; |
3987 |
17 Nov 10 |
gregory |
28 |
import org.proteios.ContextEnabled; |
3987 |
17 Nov 10 |
gregory |
29 |
import org.proteios.FileContext; |
3987 |
17 Nov 10 |
gregory |
30 |
import org.proteios.action.ProteiosAction; |
3987 |
17 Nov 10 |
gregory |
31 |
import org.proteios.gui.Toolbar; |
3987 |
17 Nov 10 |
gregory |
32 |
import org.proteios.gui.form.Fieldset; |
3987 |
17 Nov 10 |
gregory |
33 |
import org.proteios.gui.form.Form; |
3987 |
17 Nov 10 |
gregory |
34 |
import org.proteios.gui.form.FormFactory; |
3987 |
17 Nov 10 |
gregory |
35 |
import org.proteios.gui.form.TextField; |
3987 |
17 Nov 10 |
gregory |
36 |
import org.proteios.gui.Title; |
3987 |
17 Nov 10 |
gregory |
37 |
import org.proteios.gui.layout.RowLayout; |
3987 |
17 Nov 10 |
gregory |
38 |
import se.lu.thep.waf.ActionException; |
3987 |
17 Nov 10 |
gregory |
39 |
import se.lu.thep.waf.constraints.InvalidParameterValue; |
3987 |
17 Nov 10 |
gregory |
40 |
import se.lu.thep.waf.constraints.VString; |
3987 |
17 Nov 10 |
gregory |
41 |
|
3987 |
17 Nov 10 |
gregory |
42 |
/** |
3987 |
17 Nov 10 |
gregory |
* This action presents a form to the user where he/she can enter a prefix. |
3987 |
17 Nov 10 |
gregory |
44 |
* |
3987 |
17 Nov 10 |
gregory |
* @author gregory |
3987 |
17 Nov 10 |
gregory |
46 |
*/ |
3987 |
17 Nov 10 |
gregory |
47 |
public class ImportXFileForm |
3987 |
17 Nov 10 |
gregory |
48 |
extends ProteiosAction<ImportXFileForm> |
3987 |
17 Nov 10 |
gregory |
49 |
implements ContextEnabled |
3987 |
17 Nov 10 |
gregory |
50 |
{ |
3987 |
17 Nov 10 |
gregory |
51 |
/** |
3987 |
17 Nov 10 |
gregory |
* The prefix added to each file that is imported, 1-12 characters long. |
3987 |
17 Nov 10 |
gregory |
53 |
*/ |
3987 |
17 Nov 10 |
gregory |
54 |
public static final VString VPREFIX = new VString("prefix", 1, 12, true); |
3987 |
17 Nov 10 |
gregory |
55 |
|
3987 |
17 Nov 10 |
gregory |
56 |
|
3987 |
17 Nov 10 |
gregory |
57 |
@Override |
3987 |
17 Nov 10 |
gregory |
58 |
protected void runMe() |
3987 |
17 Nov 10 |
gregory |
59 |
throws ActionException, InvalidParameterValue |
3987 |
17 Nov 10 |
gregory |
60 |
{ |
3987 |
17 Nov 10 |
gregory |
61 |
/* |
3987 |
17 Nov 10 |
gregory |
* Get the id's of all selected files. FormFactory.VID is the valid |
3987 |
17 Nov 10 |
gregory |
* identifier used when rendering the list of files, thus we use it to |
3987 |
17 Nov 10 |
gregory |
* get the valid list of item ids. |
3987 |
17 Nov 10 |
gregory |
65 |
*/ |
3987 |
17 Nov 10 |
gregory |
66 |
List<Integer> files = getValidIntegerList(FormFactory.VID); |
3987 |
17 Nov 10 |
gregory |
67 |
/* |
3987 |
17 Nov 10 |
gregory |
* Make sure at least one file has been selected |
3987 |
17 Nov 10 |
gregory |
69 |
*/ |
3987 |
17 Nov 10 |
gregory |
70 |
if (files == null || files.size() == 0) |
3987 |
17 Nov 10 |
gregory |
71 |
{ |
3987 |
17 Nov 10 |
gregory |
72 |
setError("Please select at least one file to import"); |
3987 |
17 Nov 10 |
gregory |
73 |
return; |
3987 |
17 Nov 10 |
gregory |
74 |
} |
3987 |
17 Nov 10 |
gregory |
75 |
else |
3987 |
17 Nov 10 |
gregory |
76 |
{ |
3987 |
17 Nov 10 |
gregory |
77 |
/* |
3987 |
17 Nov 10 |
gregory |
* Create a form with additional parameters for the plugin. |
3987 |
17 Nov 10 |
gregory |
79 |
*/ |
3987 |
17 Nov 10 |
gregory |
80 |
Form form = new Form("xfileform"); |
3987 |
17 Nov 10 |
gregory |
81 |
Fieldset fieldSet = new Fieldset(); |
3987 |
17 Nov 10 |
gregory |
82 |
form.addFieldset(fieldSet); |
3987 |
17 Nov 10 |
gregory |
83 |
fieldSet.setTitle(new Title("Import properties")); |
3987 |
17 Nov 10 |
gregory |
84 |
/* |
3987 |
17 Nov 10 |
gregory |
* First add the selected file id's as hidden fields. If you don't |
3987 |
17 Nov 10 |
gregory |
* do this the selected file id's will be lost when clicking on the |
3987 |
17 Nov 10 |
gregory |
* next button. |
3987 |
17 Nov 10 |
gregory |
88 |
*/ |
3987 |
17 Nov 10 |
gregory |
89 |
for (Integer fileId : files) |
3987 |
17 Nov 10 |
gregory |
90 |
{ |
3987 |
17 Nov 10 |
gregory |
91 |
TextField<Integer> field = new TextField<Integer>( |
3987 |
17 Nov 10 |
gregory |
92 |
FormFactory.VID).setHidden(true); |
3987 |
17 Nov 10 |
gregory |
93 |
field.setValue(fileId); |
3987 |
17 Nov 10 |
gregory |
94 |
fieldSet.add(field); |
3987 |
17 Nov 10 |
gregory |
95 |
} |
3987 |
17 Nov 10 |
gregory |
96 |
/* |
3987 |
17 Nov 10 |
gregory |
* Then add an optional parameter. We'll add a string field. This |
3987 |
17 Nov 10 |
gregory |
* will be the prefix add to each file that has been "imported". |
3987 |
17 Nov 10 |
gregory |
99 |
*/ |
3987 |
17 Nov 10 |
gregory |
100 |
TextField<String> prefix = new TextField<String>(VPREFIX); |
3987 |
17 Nov 10 |
gregory |
101 |
prefix.setLabel(getLocale().get("Prefix")); |
3987 |
17 Nov 10 |
gregory |
102 |
fieldSet.add(prefix); |
3987 |
17 Nov 10 |
gregory |
103 |
/* |
3987 |
17 Nov 10 |
gregory |
* Add the toolbar with one button labeled 'Next' to the form. |
3987 |
17 Nov 10 |
gregory |
105 |
*/ |
3987 |
17 Nov 10 |
gregory |
106 |
Toolbar toolbar = new Toolbar(); |
3987 |
17 Nov 10 |
gregory |
107 |
ActionLink next = getActionFactory().getActionLink( |
3987 |
17 Nov 10 |
gregory |
108 |
CreateXFileImportJob.class, getLocale().get("Next")); |
3987 |
17 Nov 10 |
gregory |
109 |
toolbar.add(next); |
3987 |
17 Nov 10 |
gregory |
110 |
form.setToolbar(toolbar); |
3987 |
17 Nov 10 |
gregory |
111 |
/* |
3987 |
17 Nov 10 |
gregory |
* Build and set the layout used to display our form |
3987 |
17 Nov 10 |
gregory |
113 |
*/ |
3987 |
17 Nov 10 |
gregory |
114 |
RowLayout layout = getLayoutFactory().getRowLayout(); |
3987 |
17 Nov 10 |
gregory |
115 |
layout.add(form); |
3987 |
17 Nov 10 |
gregory |
116 |
setLayout(layout); |
3987 |
17 Nov 10 |
gregory |
117 |
} |
3987 |
17 Nov 10 |
gregory |
118 |
} |
3987 |
17 Nov 10 |
gregory |
119 |
|
3987 |
17 Nov 10 |
gregory |
120 |
|
3987 |
17 Nov 10 |
gregory |
121 |
/** |
3987 |
17 Nov 10 |
gregory |
* Tell the application in which context this action should be available |
3987 |
17 Nov 10 |
gregory |
123 |
*/ |
3987 |
17 Nov 10 |
gregory |
124 |
public List<Context> listContexts() |
3987 |
17 Nov 10 |
gregory |
125 |
{ |
3987 |
17 Nov 10 |
gregory |
126 |
List<Context> contexts = new ArrayList<Context>(1); |
3987 |
17 Nov 10 |
gregory |
127 |
/* |
3987 |
17 Nov 10 |
gregory |
* We want our action to appear as an extension when viewing files. Do |
3987 |
17 Nov 10 |
gregory |
* this by adding a FileContext to the list of contexts. |
3987 |
17 Nov 10 |
gregory |
130 |
*/ |
3987 |
17 Nov 10 |
gregory |
131 |
FileContext files = new FileContext("ifc", "Import File[s] X", |
3987 |
17 Nov 10 |
gregory |
132 |
ImportXFileForm.class); |
3987 |
17 Nov 10 |
gregory |
133 |
contexts.add(files); |
3987 |
17 Nov 10 |
gregory |
134 |
return contexts; |
3987 |
17 Nov 10 |
gregory |
135 |
} |
3987 |
17 Nov 10 |
gregory |
136 |
} |