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 / DocumentContextMenu.java @ 40558
History | View | Annotate | Download (3.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.gui; |
25 |
|
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Arrays; |
30 |
import java.util.List; |
31 |
|
32 |
import javax.swing.JMenuItem; |
33 |
import javax.swing.JPopupMenu; |
34 |
|
35 |
import org.gvsig.app.project.ProjectManager; |
36 |
import org.gvsig.app.project.documents.Document; |
37 |
import org.gvsig.app.project.documents.DocumentAction; |
38 |
import org.gvsig.app.project.documents.DocumentActionGroup; |
39 |
|
40 |
public class DocumentContextMenu extends JPopupMenu { |
41 |
|
42 |
/**
|
43 |
*
|
44 |
*/
|
45 |
private static final long serialVersionUID = -8153469580038240864L; |
46 |
|
47 |
private Document item; |
48 |
private List<Document> seleteds; |
49 |
private List<DocumentAction> actions = null; |
50 |
|
51 |
public DocumentContextMenu(String doctype, Document document, |
52 |
Document[] seletedDocuments) { |
53 |
super();
|
54 |
|
55 |
List<DocumentAction> allActions =
|
56 |
ProjectManager.getInstance().getDocumentActions(doctype); |
57 |
List<DocumentAction> actions = new ArrayList<DocumentAction>(); |
58 |
DocumentActionGroup group = null;
|
59 |
|
60 |
this.item = document;
|
61 |
this.seleteds = Arrays.asList(seletedDocuments); |
62 |
if (allActions != null) { |
63 |
for (DocumentAction action : allActions) {
|
64 |
if (action.isVisible(document, this.seleteds)) { |
65 |
actions.add(action); |
66 |
// Create menu item
|
67 |
MenuItem item = new MenuItem(action.getTitle(), action); |
68 |
|
69 |
item.setEnabled(action |
70 |
.isAvailable(this.item, this.seleteds)); |
71 |
if (!action.getGroup().equals(group)) {
|
72 |
if (group != null) { |
73 |
this.addSeparator();
|
74 |
} |
75 |
group = action.getGroup(); |
76 |
} |
77 |
this.add(item);
|
78 |
|
79 |
} |
80 |
} |
81 |
} |
82 |
this.actions = actions;
|
83 |
} |
84 |
|
85 |
public boolean hasActions() { |
86 |
return actions != null || actions.size() > 0; |
87 |
} |
88 |
|
89 |
private class MenuItem extends JMenuItem implements ActionListener { |
90 |
|
91 |
/**
|
92 |
*
|
93 |
*/
|
94 |
private static final long serialVersionUID = -752624469241001299L; |
95 |
private DocumentAction action;
|
96 |
|
97 |
public MenuItem(String text, DocumentAction action) { |
98 |
super(text);
|
99 |
this.action = action;
|
100 |
String tip = this.action.getDescription(); |
101 |
if (tip != null && tip.length() > 0) { |
102 |
this.setToolTipText(tip);
|
103 |
} |
104 |
this.addActionListener(this); |
105 |
} |
106 |
|
107 |
public void actionPerformed(ActionEvent e) { |
108 |
this.action.execute(DocumentContextMenu.this.item,
|
109 |
DocumentContextMenu.this.seleteds); |
110 |
} |
111 |
} |
112 |
|
113 |
} |