gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / JImportHelpController.java @ 478
History | View | Annotate | Download (4.54 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.io.File; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URL; |
8 |
import javax.swing.JComponent; |
9 |
import javax.swing.JFileChooser; |
10 |
import javax.swing.JOptionPane; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.gvsig.scripting.ScriptingManager; |
13 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
14 |
import org.gvsig.scripting.swing.impl.DialogPanel; |
15 |
import org.gvsig.tools.ToolsLocator; |
16 |
import org.gvsig.tools.task.SimpleTaskStatus; |
17 |
import org.slf4j.Logger; |
18 |
import org.slf4j.LoggerFactory; |
19 |
|
20 |
public class JImportHelpController extends JImportHelpView implements DialogPanel { |
21 |
|
22 |
protected static final Logger logger = LoggerFactory.getLogger(JImportHelpController.class); |
23 |
|
24 |
private final ScriptingUIManager uimanager; |
25 |
private final ScriptingManager manager; |
26 |
|
27 |
public JImportHelpController(ScriptingUIManager uimanager, DefaultJScriptingComposer composer) {
|
28 |
this.uimanager = uimanager;
|
29 |
this.manager = this.uimanager.getManager(); |
30 |
|
31 |
initComponents(); |
32 |
} |
33 |
|
34 |
private void initComponents() { |
35 |
this.btnBrowse.addActionListener(new ActionListener() { |
36 |
@Override
|
37 |
public void actionPerformed(ActionEvent e) { |
38 |
doBrowse(); |
39 |
} |
40 |
}); |
41 |
} |
42 |
|
43 |
public void actionAccept() { |
44 |
File folder = this.getFolder(); |
45 |
String name = this.txtName.getText(); |
46 |
if (folder == null) { |
47 |
JOptionPane.showMessageDialog(null, |
48 |
this.uimanager.getTranslation("JavaDoc_Error"), |
49 |
"Import JavaDoc",
|
50 |
JOptionPane.WARNING_MESSAGE
|
51 |
); |
52 |
return;
|
53 |
} |
54 |
if (StringUtils.isEmpty(name)) {
|
55 |
JOptionPane.showMessageDialog(null, |
56 |
this.uimanager.getTranslation("Name_blank"), |
57 |
"Import JavaDoc",
|
58 |
JOptionPane.WARNING_MESSAGE
|
59 |
); |
60 |
return;
|
61 |
} |
62 |
if (this.manager.getHelpManager().existsHelp(name)) { |
63 |
JOptionPane.showMessageDialog(null, |
64 |
this.uimanager.getTranslation("Name_exists"), |
65 |
"Import JavaDoc",
|
66 |
JOptionPane.WARNING_MESSAGE
|
67 |
); |
68 |
return;
|
69 |
} |
70 |
File packageListFile = new File(folder, "package-list"); |
71 |
if (!packageListFile.exists()) {
|
72 |
JOptionPane.showMessageDialog(null, |
73 |
"This folder haven't got a 'package-list' file to make the JavaDoc\nPlease, choose another one",
|
74 |
"Import JavaDoc",
|
75 |
JOptionPane.WARNING_MESSAGE
|
76 |
); |
77 |
return;
|
78 |
} |
79 |
SimpleTaskStatus taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Import_javadoc");
|
80 |
taskStatus.setAutoremove(true);
|
81 |
taskStatus.add(); |
82 |
boolean ok = this.manager.getHelpManager().importJavadoc(name, folder, taskStatus); |
83 |
setVisible(false);
|
84 |
if (ok) {
|
85 |
JOptionPane.showMessageDialog(null, |
86 |
this.uimanager.getTranslation("Import_success"), |
87 |
this.uimanager.getTranslation("Success"), |
88 |
JOptionPane.INFORMATION_MESSAGE
|
89 |
); |
90 |
} else {
|
91 |
JOptionPane.showMessageDialog(null, |
92 |
this.uimanager.getTranslation("Cant_import_javadoc"), |
93 |
this.uimanager.getTranslation("Problems"), |
94 |
JOptionPane.INFORMATION_MESSAGE
|
95 |
); |
96 |
} |
97 |
} |
98 |
|
99 |
public void actionCancel() { |
100 |
setVisible(false);
|
101 |
} |
102 |
|
103 |
public void doBrowse() { |
104 |
final JFileChooser fc = new JFileChooser(); |
105 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
106 |
int returnVal = fc.showOpenDialog(this); |
107 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
108 |
File file = fc.getSelectedFile();
|
109 |
this.txtFolder.setText(file.getAbsolutePath());
|
110 |
} |
111 |
} |
112 |
|
113 |
public File getFolder() { |
114 |
String s = this.txtFolder.getText(); |
115 |
if (StringUtils.isEmpty(s)) {
|
116 |
return null; |
117 |
} |
118 |
File f = new File(s); |
119 |
return f;
|
120 |
} |
121 |
|
122 |
@Override
|
123 |
public JComponent getJComponent() { |
124 |
return this; |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public void actionApply() { |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public boolean isVisibleAccept() { |
133 |
return true; |
134 |
} |
135 |
|
136 |
@Override
|
137 |
public boolean isVisibleApply() { |
138 |
return false; |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public boolean isVisibleCancel() { |
143 |
return true; |
144 |
} |
145 |
} |