svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / gui / projectpanel / ProjectDocumentsPanelPage.java @ 46033
History | View | Annotate | Download (19.2 KB)
1 | 43913 | jjdelcerro | package org.gvsig.app.project.documents.gui.projectpanel; |
---|---|---|---|
2 | 41350 | jjdelcerro | |
3 | 43913 | jjdelcerro | import java.awt.BorderLayout; |
4 | import org.gvsig.app.project.documents.gui.*; |
||
5 | 41350 | jjdelcerro | import java.awt.Dimension; |
6 | import java.awt.FlowLayout; |
||
7 | 43913 | jjdelcerro | import java.awt.event.ActionEvent; |
8 | import java.awt.event.ActionListener; |
||
9 | import java.awt.event.ComponentAdapter; |
||
10 | import java.awt.event.ComponentEvent; |
||
11 | 44484 | jjdelcerro | import java.awt.event.MouseAdapter; |
12 | import java.awt.event.MouseEvent; |
||
13 | 43913 | jjdelcerro | import java.beans.PropertyChangeEvent; |
14 | import java.beans.PropertyChangeListener; |
||
15 | 41350 | jjdelcerro | import java.io.File; |
16 | 43913 | jjdelcerro | import java.util.Collections; |
17 | import java.util.Comparator; |
||
18 | import java.util.Iterator; |
||
19 | import java.util.List; |
||
20 | import javax.swing.ButtonGroup; |
||
21 | 41350 | jjdelcerro | import javax.swing.JComponent; |
22 | 44502 | omartinez | import javax.swing.JLabel; |
23 | import javax.swing.JList; |
||
24 | 43913 | jjdelcerro | import javax.swing.JOptionPane; |
25 | 41350 | jjdelcerro | import javax.swing.JPanel; |
26 | 43913 | jjdelcerro | import javax.swing.JRadioButton; |
27 | 41350 | jjdelcerro | import javax.swing.JScrollPane; |
28 | 43913 | jjdelcerro | import javax.swing.ScrollPaneConstants; |
29 | import javax.swing.SwingUtilities; |
||
30 | import javax.swing.event.ListSelectionEvent; |
||
31 | import javax.swing.event.ListSelectionListener; |
||
32 | import org.apache.commons.lang3.StringUtils; |
||
33 | 41350 | jjdelcerro | import org.gvsig.andami.PluginServices; |
34 | 43913 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.IWindow; |
35 | import org.gvsig.andami.ui.mdiManager.MDIManager; |
||
36 | import org.gvsig.app.ApplicationLocator; |
||
37 | import org.gvsig.app.ApplicationManager; |
||
38 | 41350 | jjdelcerro | import org.gvsig.app.project.Project; |
39 | 43913 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
40 | import org.gvsig.app.project.documents.Document; |
||
41 | import org.gvsig.app.project.documents.DocumentManager; |
||
42 | 41350 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
43 | import org.gvsig.tools.i18n.I18nManager; |
||
44 | 43913 | jjdelcerro | import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
45 | import org.gvsig.tools.observer.Observable; |
||
46 | import org.gvsig.tools.observer.Observer; |
||
47 | 41350 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 | 43913 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingManager; |
49 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
50 | 45931 | jjdelcerro | import org.gvsig.tools.util.Invocable; |
51 | 43913 | jjdelcerro | import org.gvsig.utils.DefaultListModel; |
52 | import org.slf4j.Logger; |
||
53 | import org.slf4j.LoggerFactory; |
||
54 | 41350 | jjdelcerro | |
55 | 43913 | jjdelcerro | public class ProjectDocumentsPanelPage |
56 | extends ProjectDocumentsPanelPageView
|
||
57 | implements ProjectPanelPage {
|
||
58 | |||
59 | private final Logger LOG = LoggerFactory.getLogger(ProjectGeneralPropertiesPage.class); |
||
60 | 41350 | jjdelcerro | |
61 | 43913 | jjdelcerro | private Project project;
|
62 | private DocumentManager currentDocumentType;
|
||
63 | private final PropertyChangeListener projectPropertyChangeListener; |
||
64 | private final Observer projectObserver; |
||
65 | 41350 | jjdelcerro | |
66 | 43913 | jjdelcerro | public ProjectDocumentsPanelPage() {
|
67 | this.project = null; |
||
68 | this.projectPropertyChangeListener = new PropertyChangeListener() { |
||
69 | @Override
|
||
70 | public void propertyChange(PropertyChangeEvent evt) { |
||
71 | updateProject(); |
||
72 | } |
||
73 | }; |
||
74 | this.projectObserver = new Observer() { |
||
75 | @Override
|
||
76 | public void update(Observable observable, Object notification) { |
||
77 | updateProject(); |
||
78 | } |
||
79 | }; |
||
80 | this.initComponents();
|
||
81 | } |
||
82 | 41350 | jjdelcerro | |
83 | 43913 | jjdelcerro | @Override
|
84 | public void setData(Object data) { |
||
85 | 41350 | jjdelcerro | } |
86 | 43913 | jjdelcerro | |
87 | @Override
|
||
88 | public String getTitle() { |
||
89 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
90 | 44477 | jjdelcerro | return i18n.getTranslation("_Documents"); |
91 | 43913 | jjdelcerro | } |
92 | 41350 | jjdelcerro | |
93 | 43913 | jjdelcerro | @Override
|
94 | public int getPriority() { |
||
95 | return 1000; |
||
96 | } |
||
97 | |||
98 | @Override
|
||
99 | 41350 | jjdelcerro | public boolean whenAccept() { |
100 | 43913 | jjdelcerro | return true; |
101 | 41350 | jjdelcerro | } |
102 | |||
103 | 43913 | jjdelcerro | @Override
|
104 | 41350 | jjdelcerro | public boolean whenApply() { |
105 | return true; |
||
106 | } |
||
107 | |||
108 | 43913 | jjdelcerro | @Override
|
109 | 41350 | jjdelcerro | public boolean whenCancel() { |
110 | return true; |
||
111 | } |
||
112 | |||
113 | 43913 | jjdelcerro | @Override
|
114 | 41350 | jjdelcerro | public JComponent asJComponent() { |
115 | return this; |
||
116 | } |
||
117 | |||
118 | private void initComponents() { |
||
119 | 43913 | jjdelcerro | this.initDocumentTypes();
|
120 | this.btnDocumentNew.addActionListener(new ActionListener() { |
||
121 | @Override
|
||
122 | public void actionPerformed(ActionEvent e) { |
||
123 | doDocumentNew(); |
||
124 | } |
||
125 | }); |
||
126 | this.btnDocumentOpen.addActionListener(new ActionListener() { |
||
127 | @Override
|
||
128 | public void actionPerformed(ActionEvent e) { |
||
129 | doDocumentOpen(); |
||
130 | } |
||
131 | }); |
||
132 | this.btnDocumentRename.addActionListener(new ActionListener() { |
||
133 | @Override
|
||
134 | public void actionPerformed(ActionEvent e) { |
||
135 | doDocumentRename(); |
||
136 | } |
||
137 | }); |
||
138 | this.btnDocumentDelete.addActionListener(new ActionListener() { |
||
139 | @Override
|
||
140 | public void actionPerformed(ActionEvent e) { |
||
141 | doDocumentDelete(); |
||
142 | } |
||
143 | }); |
||
144 | this.btnDocumentProperties.addActionListener(new ActionListener() { |
||
145 | @Override
|
||
146 | public void actionPerformed(ActionEvent e) { |
||
147 | doDocumentProperties(); |
||
148 | } |
||
149 | }); |
||
150 | this.btnProjectProperties.addActionListener(new ActionListener() { |
||
151 | @Override
|
||
152 | public void actionPerformed(ActionEvent e) { |
||
153 | doProjectProperties(); |
||
154 | } |
||
155 | }); |
||
156 | this.lstDocuments.addListSelectionListener(new ListSelectionListener() { |
||
157 | @Override
|
||
158 | public void valueChanged(ListSelectionEvent e) { |
||
159 | if (e.getValueIsAdjusting()) {
|
||
160 | return;
|
||
161 | } |
||
162 | doDocumentsSelectionChanged(); |
||
163 | } |
||
164 | }); |
||
165 | 44484 | jjdelcerro | this.lstDocuments.addMouseListener(new MouseAdapter() { |
166 | @Override
|
||
167 | public void mouseClicked(MouseEvent e) { |
||
168 | if( e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2 ) { |
||
169 | doDocumentOpen(); |
||
170 | } |
||
171 | } |
||
172 | }); |
||
173 | 43913 | jjdelcerro | this.translate();
|
174 | 41350 | jjdelcerro | } |
175 | |||
176 | 43913 | jjdelcerro | private void translate() { |
177 | ToolsSwingManager manager = ToolsSwingLocator.getToolsSwingManager(); |
||
178 | manager.translate(this.lblCreationDate);
|
||
179 | manager.translate(this.lblSavedIn);
|
||
180 | manager.translate(this.lblSessionName);
|
||
181 | manager.translate(this.lblDocument);
|
||
182 | manager.translate(this.lblDocumentTypes);
|
||
183 | manager.translate(this.lblSessionProperties);
|
||
184 | manager.translate(this.lblCreationDate);
|
||
185 | manager.translate(this.lblCreationDate);
|
||
186 | manager.translate(this.lblCreationDate);
|
||
187 | manager.translate(this.lblCreationDate);
|
||
188 | manager.translate(this.lblCreationDate);
|
||
189 | manager.translate(this.lblCreationDate);
|
||
190 | 43923 | jjdelcerro | |
191 | manager.translate(this.btnDocumentDelete);
|
||
192 | manager.translate(this.btnDocumentNew);
|
||
193 | manager.translate(this.btnDocumentOpen);
|
||
194 | manager.translate(this.btnDocumentProperties);
|
||
195 | manager.translate(this.btnDocumentRename);
|
||
196 | manager.translate(this.btnProjectProperties);
|
||
197 | |||
198 | 41350 | jjdelcerro | } |
199 | |||
200 | 43913 | jjdelcerro | @Override
|
201 | public void setProject(Project project) { |
||
202 | if( this.project!=null ) { |
||
203 | this.project.removePropertyChangeListener(this.projectPropertyChangeListener); |
||
204 | this.project.deleteObserver(this.projectObserver); |
||
205 | 41350 | jjdelcerro | } |
206 | 43913 | jjdelcerro | this.project = project;
|
207 | if(project!=null){ |
||
208 | project.addPropertyChangeListener(this.projectPropertyChangeListener);
|
||
209 | project.addObserver(this.projectObserver);
|
||
210 | } |
||
211 | updateProject(); |
||
212 | 41350 | jjdelcerro | } |
213 | |||
214 | 43913 | jjdelcerro | private void updateProject() { |
215 | if( !SwingUtilities.isEventDispatchThread() ) { |
||
216 | SwingUtilities.invokeLater(new Runnable() { |
||
217 | @Override
|
||
218 | public void run() { |
||
219 | updateProject(); |
||
220 | } |
||
221 | }); |
||
222 | return;
|
||
223 | 41350 | jjdelcerro | } |
224 | 43913 | jjdelcerro | updateProjectDocumens(); |
225 | updateProjectProperties(); |
||
226 | 41350 | jjdelcerro | } |
227 | 43913 | jjdelcerro | |
228 | private void updateProjectProperties() { |
||
229 | if (project != null) { |
||
230 | this.txtSessionName.setText(project.getName());
|
||
231 | File path = this.project.getFile(); |
||
232 | if (path != null) { |
||
233 | this.txtSavedIn.setText(path.toString());
|
||
234 | } else {
|
||
235 | this.txtSavedIn.setText(""); |
||
236 | } |
||
237 | this.txtCreationDate.setText(project.getCreationDate());
|
||
238 | 41350 | jjdelcerro | } |
239 | 43913 | jjdelcerro | } |
240 | |||
241 | private void initDocumentTypes() { |
||
242 | SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
||
243 | 41350 | jjdelcerro | |
244 | 43913 | jjdelcerro | this.documentTypesContainer.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
245 | 41350 | jjdelcerro | |
246 | 43913 | jjdelcerro | List<DocumentManager> factories = ProjectManager.getInstance().getDocumentManagers();
|
247 | Collections.sort(factories, new Comparator<DocumentManager>() { |
||
248 | 41350 | jjdelcerro | |
249 | 43913 | jjdelcerro | @Override
|
250 | public int compare(DocumentManager arg0, DocumentManager arg1) { |
||
251 | return arg0.getPriority() - arg1.getPriority();
|
||
252 | } |
||
253 | 41350 | jjdelcerro | |
254 | 43913 | jjdelcerro | }); |
255 | this.currentDocumentType = factories.get(0); |
||
256 | JRadioButton selectButton = null; |
||
257 | ButtonGroup group = new ButtonGroup(); |
||
258 | JPanel panel = new JPanel(); |
||
259 | for (DocumentManager documentFactory : factories) {
|
||
260 | if (!identityManager.getCurrentIdentity().isAuthorized(
|
||
261 | Document.ACCESS_DOCUMENT_AUTHORIZATION,
|
||
262 | documentFactory, |
||
263 | documentFactory.getTypeName())) { |
||
264 | continue;
|
||
265 | } |
||
266 | JRadioButton button = this.createDocumentTypeButton(documentFactory); |
||
267 | group.add(button); |
||
268 | panel.add(button); |
||
269 | if( documentFactory == this.currentDocumentType ) { |
||
270 | selectButton = button; |
||
271 | } |
||
272 | 41350 | jjdelcerro | } |
273 | 44502 | omartinez | |
274 | 43913 | jjdelcerro | JScrollPane scroll = new JScrollPane(panel); |
275 | Dimension dim = panel.getPreferredSize();
|
||
276 | 44502 | omartinez | scroll.setMinimumSize(new Dimension(dim.width+2, dim.height + 35)); |
277 | 43913 | jjdelcerro | scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
278 | scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
279 | 41350 | jjdelcerro | |
280 | 43913 | jjdelcerro | this.documentTypesContainer.setLayout(new BorderLayout()); |
281 | this.documentTypesContainer.add(scroll, BorderLayout.CENTER); |
||
282 | selectButton.setSelected(true);
|
||
283 | 41350 | jjdelcerro | } |
284 | 44502 | omartinez | |
285 | 43913 | jjdelcerro | private JRadioButton createDocumentTypeButton(final DocumentManager documentFactory) { |
286 | final JRadioButton rb = new JRadioButton(); |
||
287 | 41350 | jjdelcerro | |
288 | 43913 | jjdelcerro | rb.setIcon(documentFactory.getIcon()); |
289 | rb.setSelectedIcon(documentFactory.getIconSelected()); |
||
290 | rb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); |
||
291 | rb.setText(documentFactory.getTitle()); |
||
292 | rb.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); |
||
293 | rb.setName(documentFactory.getTypeName()); |
||
294 | rb.addChangeListener(new javax.swing.event.ChangeListener() {
|
||
295 | @Override
|
||
296 | public void stateChanged(javax.swing.event.ChangeEvent e) { |
||
297 | if (rb.isSelected()) {
|
||
298 | currentDocumentType = documentFactory; |
||
299 | updateProjectDocumens(); |
||
300 | } |
||
301 | } |
||
302 | }); |
||
303 | return rb;
|
||
304 | 41350 | jjdelcerro | } |
305 | |||
306 | 43913 | jjdelcerro | private void openDocumentWindow(Document doc) { |
307 | if (doc == null) { |
||
308 | return;
|
||
309 | 41350 | jjdelcerro | } |
310 | 43913 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
311 | ApplicationManager application = ApplicationLocator.getManager(); |
||
312 | IWindow window = doc.getFactory().getMainWindow(doc); |
||
313 | if (window == null) { |
||
314 | application.message( |
||
315 | i18n.getTranslation("error_opening_the_document"),
|
||
316 | JOptionPane.WARNING_MESSAGE
|
||
317 | ); |
||
318 | return;
|
||
319 | } |
||
320 | application.getUIManager().addWindow( |
||
321 | window, |
||
322 | MDIManager.ALIGN_FIRST_LINE_END_CASCADE |
||
323 | ); |
||
324 | project.setModified(true);
|
||
325 | 41350 | jjdelcerro | } |
326 | |||
327 | 43913 | jjdelcerro | private void updateProjectDocumens() { |
328 | if (project == null) { |
||
329 | return;
|
||
330 | 41350 | jjdelcerro | } |
331 | 43913 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
332 | this.lblDocument.setText(i18n.getTranslation("documentos_existentes")); |
||
333 | 41350 | jjdelcerro | |
334 | 43913 | jjdelcerro | String documentsTypeName = this.currentDocumentType.getTypeName(); |
335 | List<Document> documents = project.getDocuments(documentsTypeName); |
||
336 | DefaultListModel model = new DefaultListModel(documents); |
||
337 | this.lstDocuments.setModel(model);
|
||
338 | this.lblDocument.setText(currentDocumentType.getTitle());
|
||
339 | updateDocumentButtons(); |
||
340 | 41350 | jjdelcerro | } |
341 | |||
342 | 43913 | jjdelcerro | private void updateDocumentButtons() { |
343 | this.btnDocumentNew.setEnabled(true); |
||
344 | if (this.lstDocuments.getSelectedIndex() != -1) { |
||
345 | this.btnDocumentOpen.setEnabled(true); |
||
346 | this.btnDocumentDelete.setEnabled(true); |
||
347 | this.btnDocumentRename.setEnabled(true); |
||
348 | this.btnDocumentProperties.setEnabled(true); |
||
349 | } else {
|
||
350 | btnDocumentOpen.setEnabled(false);
|
||
351 | btnDocumentDelete.setEnabled(false);
|
||
352 | btnDocumentRename.setEnabled(false);
|
||
353 | btnDocumentProperties.setEnabled(false);
|
||
354 | 41350 | jjdelcerro | } |
355 | } |
||
356 | |||
357 | 43913 | jjdelcerro | private void doDocumentNew() { |
358 | String documentsTypeName = this.currentDocumentType.getTypeName(); |
||
359 | ProjectManager projectManager = ProjectManager.getInstance(); |
||
360 | 45931 | jjdelcerro | Iterator<? extends Document> documents = projectManager.createDocumentsByUser(documentsTypeName, new Invocable() { |
361 | @Override
|
||
362 | public Object call(Object... args) { |
||
363 | Iterator<? extends Document> docs = (Iterator<? extends Document>) args[0]; |
||
364 | addNewDocuments(docs); |
||
365 | return null; |
||
366 | } |
||
367 | }); |
||
368 | addNewDocuments(documents); |
||
369 | } |
||
370 | |||
371 | private void addNewDocuments(Iterator<? extends Document> documents) { |
||
372 | 43913 | jjdelcerro | while ( documents != null && documents.hasNext() ) { |
373 | try {
|
||
374 | Document document = documents.next();
|
||
375 | project.addDocument(document); |
||
376 | openDocumentWindow(document); |
||
377 | } catch (Exception e) { |
||
378 | LOG.warn("Can't open document", e);
|
||
379 | } |
||
380 | 41350 | jjdelcerro | } |
381 | 43913 | jjdelcerro | this.lstDocuments.requestFocus();
|
382 | this.lstDocuments.setSelectedIndex(this.lstDocuments.getModel().getSize()-1); |
||
383 | 41350 | jjdelcerro | } |
384 | |||
385 | 43913 | jjdelcerro | private void doDocumentOpen() { |
386 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
387 | ApplicationManager application = ApplicationLocator.getManager(); |
||
388 | 41350 | jjdelcerro | |
389 | 43913 | jjdelcerro | int[] indexes = this.lstDocuments.getSelectedIndices(); |
390 | for (int i = indexes.length - 1; i >= 0; i--) { |
||
391 | int index = indexes[i];
|
||
392 | if (index == -1) { |
||
393 | return;
|
||
394 | } |
||
395 | String documentsTypeName = this.currentDocumentType.getTypeName(); |
||
396 | List<Document> documents = project.getDocuments(documentsTypeName); |
||
397 | Document doc = documents.get(index);
|
||
398 | if (!doc.isAvailable()) {
|
||
399 | application.messageDialog( |
||
400 | i18n.getTranslation("document_not_available"),
|
||
401 | i18n.getTranslation("abrir"),
|
||
402 | JOptionPane.WARNING_MESSAGE
|
||
403 | ); |
||
404 | } |
||
405 | IWindow win = doc.getMainWindow(); |
||
406 | openDocumentWindow(doc); |
||
407 | 41350 | jjdelcerro | } |
408 | |||
409 | } |
||
410 | |||
411 | 43913 | jjdelcerro | private void doDocumentRename() { |
412 | ApplicationManager application = ApplicationLocator.getManager(); |
||
413 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
414 | 41350 | jjdelcerro | |
415 | 43913 | jjdelcerro | int index = this.lstDocuments.getSelectedIndex(); |
416 | if (index == -1) { |
||
417 | return;
|
||
418 | 41350 | jjdelcerro | } |
419 | 43913 | jjdelcerro | String DoumentTypeName = this.currentDocumentType.getTypeName(); |
420 | List<Document> documents = project.getDocuments(DoumentTypeName); |
||
421 | Document doc = documents.get(index);
|
||
422 | String name = application.inputDialog(
|
||
423 | i18n.getTranslation("introduce_nombre"),
|
||
424 | i18n.getTranslation("renombrar"),
|
||
425 | JOptionPane.QUESTION_MESSAGE,
|
||
426 | doc.getName() |
||
427 | ); |
||
428 | 46033 | fdiaz | if(name != null) { |
429 | for (Document document : documents) { |
||
430 | if (StringUtils.equals(document.getName(), name)) {
|
||
431 | application.messageDialog( |
||
432 | i18n.getTranslation("elemento_ya_existe"),
|
||
433 | i18n.getTranslation("warning"),
|
||
434 | JOptionPane.WARNING_MESSAGE
|
||
435 | ); |
||
436 | return;
|
||
437 | } |
||
438 | 43913 | jjdelcerro | } |
439 | 46033 | fdiaz | doc.setName(name); |
440 | updateProjectDocumens(); |
||
441 | this.project.setModified(true); |
||
442 | 43913 | jjdelcerro | } |
443 | 41350 | jjdelcerro | } |
444 | |||
445 | 43913 | jjdelcerro | private void doDocumentDelete() { |
446 | ApplicationManager application = ApplicationLocator.getManager(); |
||
447 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
448 | 41350 | jjdelcerro | |
449 | 43913 | jjdelcerro | int res = application.confirmDialog(
|
450 | i18n.getTranslation("confirmar_borrar"),
|
||
451 | i18n.getTranslation("borrar"),
|
||
452 | JOptionPane.YES_NO_OPTION,
|
||
453 | JOptionPane.INFORMATION_MESSAGE,
|
||
454 | "Confirm remove document from project"
|
||
455 | ); |
||
456 | int lastremoved = 0; |
||
457 | if (res == JOptionPane.YES_OPTION) { |
||
458 | String DoumentTypeName = this.currentDocumentType.getTypeName(); |
||
459 | int[] indexes = this.lstDocuments.getSelectedIndices(); |
||
460 | for (int i = indexes.length - 1; i >= 0; i--) { |
||
461 | int index = indexes[i];
|
||
462 | List<Document> documents = project.getDocuments(DoumentTypeName); |
||
463 | Document doc = documents.get(index);
|
||
464 | if (doc.isLocked()) {
|
||
465 | application.messageDialog( |
||
466 | i18n.getTranslation("locked_element_it_cannot_be_deleted"),
|
||
467 | i18n.getTranslation("Information"),
|
||
468 | JOptionPane.INFORMATION_MESSAGE
|
||
469 | ); |
||
470 | return;
|
||
471 | 41350 | jjdelcerro | } |
472 | 43913 | jjdelcerro | PluginServices.getMDIManager().closeSingletonWindow(doc); |
473 | project.removeDocument(doc); |
||
474 | lastremoved = index; |
||
475 | } |
||
476 | if (lastremoved >= this.lstDocuments.getModel().getSize()) { |
||
477 | this.lstDocuments.setSelectedIndex(this.lstDocuments.getModel().getSize() - 1); |
||
478 | } else if (lastremoved >= 0) { |
||
479 | this.lstDocuments.setSelectedIndex(lastremoved);
|
||
480 | } |
||
481 | project.setModified(true);
|
||
482 | 41350 | jjdelcerro | } |
483 | |||
484 | } |
||
485 | |||
486 | 43913 | jjdelcerro | private void doDocumentProperties() { |
487 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
488 | ApplicationManager application = ApplicationLocator.getManager(); |
||
489 | |||
490 | int index = this.lstDocuments.getSelectedIndex(); |
||
491 | if (index == -1) { |
||
492 | return;
|
||
493 | 41350 | jjdelcerro | } |
494 | 43913 | jjdelcerro | String DoumentTypeName = this.currentDocumentType.getTypeName(); |
495 | List<Document> documents = project.getDocuments(DoumentTypeName); |
||
496 | Document doc = documents.get(index);
|
||
497 | if (!doc.isAvailable()) {
|
||
498 | application.messageDialog( |
||
499 | i18nManager.getTranslation("document_not_available"),
|
||
500 | i18nManager.getTranslation("properties"),
|
||
501 | JOptionPane.WARNING_MESSAGE
|
||
502 | ); |
||
503 | return;
|
||
504 | } |
||
505 | IWindow properties = doc.getFactory().getPropertiesWindow(doc); |
||
506 | application.getUIManager().addWindow( |
||
507 | properties |
||
508 | ); |
||
509 | this.lstDocuments.setSelectedIndex(index);
|
||
510 | project.setModified(true);
|
||
511 | } |
||
512 | 41350 | jjdelcerro | |
513 | 43913 | jjdelcerro | private void doProjectProperties() { |
514 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
515 | WindowManager winmgr = ToolsSwingLocator.getWindowManager(); |
||
516 | ProjectProperties panel = new ProjectProperties(project);
|
||
517 | panel.addComponentListener(new ComponentAdapter() { |
||
518 | @Override
|
||
519 | public void componentHidden(ComponentEvent e) { |
||
520 | updateProjectProperties(); |
||
521 | } |
||
522 | }); |
||
523 | winmgr.showWindow( |
||
524 | panel, |
||
525 | i18nManager.getTranslation("project_properties"),
|
||
526 | WindowManager.MODE.WINDOW |
||
527 | ); |
||
528 | 41350 | jjdelcerro | } |
529 | |||
530 | 43913 | jjdelcerro | private void doDocumentsSelectionChanged() { |
531 | this.updateDocumentButtons();
|
||
532 | } |
||
533 | 41350 | jjdelcerro | } |