svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / DocumentContextMenu.java @ 36443
History | View | Annotate | Download (3.61 KB)
1 | 36411 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | 31496 | jjdelcerro | package org.gvsig.app.project.documents.gui; |
23 | 7749 | jmvivo | |
24 | import java.awt.event.ActionEvent; |
||
25 | import java.awt.event.ActionListener; |
||
26 | import java.util.ArrayList; |
||
27 | import java.util.Arrays; |
||
28 | 31496 | jjdelcerro | import java.util.List; |
29 | 7749 | jmvivo | |
30 | import javax.swing.JMenuItem; |
||
31 | import javax.swing.JPopupMenu; |
||
32 | |||
33 | 31496 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
34 | 36411 | cordinyana | import org.gvsig.app.project.documents.Document; |
35 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.DocumentAction; |
36 | import org.gvsig.app.project.documents.DocumentActionGroup; |
||
37 | 24958 | jmvivo | |
38 | 36411 | cordinyana | public class DocumentContextMenu extends JPopupMenu { |
39 | 7749 | jmvivo | |
40 | 36411 | cordinyana | /**
|
41 | 24958 | jmvivo | *
|
42 | 7749 | jmvivo | */
|
43 | 36411 | cordinyana | private static final long serialVersionUID = -8153469580038240864L; |
44 | 24958 | jmvivo | |
45 | 36411 | cordinyana | private Document item; |
46 | private List<Document> seleteds; |
||
47 | private List<DocumentAction> actions = null; |
||
48 | 24958 | jmvivo | |
49 | 36411 | cordinyana | public DocumentContextMenu(String doctype, Document document, |
50 | Document[] seletedDocuments) { |
||
51 | super();
|
||
52 | 31496 | jjdelcerro | |
53 | 36411 | cordinyana | List<DocumentAction> allActions =
|
54 | ProjectManager.getInstance().getDocumentActions(doctype); |
||
55 | List<DocumentAction> actions = new ArrayList<DocumentAction>(); |
||
56 | DocumentActionGroup group = null;
|
||
57 | 24958 | jmvivo | |
58 | 36411 | cordinyana | this.item = document;
|
59 | this.seleteds = Arrays.asList(seletedDocuments); |
||
60 | 36443 | cordinyana | if (allActions != null) { |
61 | for (DocumentAction action : allActions) {
|
||
62 | if (action.isVisible(document, this.seleteds)) { |
||
63 | actions.add(action); |
||
64 | // Create menu item
|
||
65 | MenuItem item = new MenuItem(action.getTitle(), action); |
||
66 | 24958 | jmvivo | |
67 | 36443 | cordinyana | item.setEnabled(action |
68 | .isAvailable(this.item, this.seleteds)); |
||
69 | if (!action.getGroup().equals(group)) {
|
||
70 | if (group != null) { |
||
71 | this.addSeparator();
|
||
72 | } |
||
73 | group = action.getGroup(); |
||
74 | 36411 | cordinyana | } |
75 | 36443 | cordinyana | this.add(item);
|
76 | |||
77 | 36411 | cordinyana | } |
78 | } |
||
79 | } |
||
80 | this.actions = actions;
|
||
81 | } |
||
82 | 7749 | jmvivo | |
83 | 36411 | cordinyana | public boolean hasActions() { |
84 | return actions != null || actions.size() > 0; |
||
85 | } |
||
86 | |||
87 | private class MenuItem extends JMenuItem implements ActionListener { |
||
88 | |||
89 | /**
|
||
90 | 24958 | jmvivo | *
|
91 | */
|
||
92 | 36411 | cordinyana | private static final long serialVersionUID = -752624469241001299L; |
93 | private DocumentAction action;
|
||
94 | 24958 | jmvivo | |
95 | 36411 | cordinyana | public MenuItem(String text, DocumentAction action) { |
96 | super(text);
|
||
97 | this.action = action;
|
||
98 | String tip = this.action.getDescription(); |
||
99 | if (tip != null && tip.length() > 0) { |
||
100 | this.setToolTipText(tip);
|
||
101 | } |
||
102 | this.addActionListener(this); |
||
103 | } |
||
104 | 24958 | jmvivo | |
105 | 36411 | cordinyana | public void actionPerformed(ActionEvent e) { |
106 | this.action.execute(DocumentContextMenu.this.item,
|
||
107 | DocumentContextMenu.this.seleteds); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | 7749 | jmvivo | } |