Revision 36411 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/gui/DocumentContextMenu.java
DocumentContextMenu.java | ||
---|---|---|
1 |
/* 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 |
*/ |
|
1 | 22 |
package org.gvsig.app.project.documents.gui; |
2 | 23 |
|
3 | 24 |
import java.awt.event.ActionEvent; |
... | ... | |
10 | 31 |
import javax.swing.JPopupMenu; |
11 | 32 |
|
12 | 33 |
import org.gvsig.app.project.ProjectManager; |
34 |
import org.gvsig.app.project.documents.Document; |
|
13 | 35 |
import org.gvsig.app.project.documents.DocumentAction; |
14 | 36 |
import org.gvsig.app.project.documents.DocumentActionGroup; |
15 |
import org.gvsig.app.project.documents.Document; |
|
16 | 37 |
|
38 |
public class DocumentContextMenu extends JPopupMenu { |
|
17 | 39 |
|
18 |
public class DocumentContextMenu extends JPopupMenu { |
|
19 |
/** |
|
40 |
/** |
|
20 | 41 |
* |
21 | 42 |
*/ |
22 |
private static final long serialVersionUID = -8153469580038240864L;
|
|
43 |
private static final long serialVersionUID = -8153469580038240864L;
|
|
23 | 44 |
|
24 |
private Document item;
|
|
25 |
private List<Document> seleteds;
|
|
26 |
private List<DocumentAction> actions = null;
|
|
45 |
private Document item;
|
|
46 |
private List<Document> seleteds;
|
|
47 |
private List<DocumentAction> actions = null;
|
|
27 | 48 |
|
49 |
public DocumentContextMenu(String doctype, Document document, |
|
50 |
Document[] seletedDocuments) { |
|
51 |
super(); |
|
28 | 52 |
|
29 |
public DocumentContextMenu(String doctype, Document document, Document[] seletedDocuments) { |
|
30 |
super(); |
|
53 |
List<DocumentAction> allActions = |
|
54 |
ProjectManager.getInstance().getDocumentActions(doctype); |
|
55 |
List<DocumentAction> actions = new ArrayList<DocumentAction>(); |
|
56 |
DocumentActionGroup group = null; |
|
31 | 57 |
|
32 |
List<DocumentAction> allActions = ProjectManager.getInstance().getDocumentActions(doctype); |
|
33 |
List<DocumentAction> actions = new ArrayList<DocumentAction>(); |
|
34 |
DocumentActionGroup group = null; |
|
35 |
|
|
36 |
this.item = document; |
|
37 |
this.seleteds = Arrays.asList( seletedDocuments); |
|
38 |
for (DocumentAction action : allActions) { |
|
39 |
if( action.isVisible(document, this.seleteds) ) { |
|
40 |
actions.add(action); |
|
41 |
// Create menu item |
|
42 |
MenuItem item = new MenuItem(action.getTitle(),action); |
|
43 |
|
|
44 |
item.setEnabled( action.isAvailable(this.item, this.seleteds)); |
|
45 |
if (!action.getGroup().equals(group)) { |
|
46 |
if (group != null) { |
|
47 |
this.addSeparator(); |
|
48 |
} |
|
49 |
group = action.getGroup(); |
|
50 |
} |
|
51 |
this.add(item); |
|
58 |
this.item = document; |
|
59 |
this.seleteds = Arrays.asList(seletedDocuments); |
|
60 |
for (DocumentAction action : allActions) { |
|
61 |
if (action.isVisible(document, this.seleteds)) { |
|
62 |
actions.add(action); |
|
63 |
// Create menu item |
|
64 |
MenuItem item = new MenuItem(action.getTitle(), action); |
|
52 | 65 |
|
53 |
} |
|
54 |
} |
|
55 |
this.actions = actions; |
|
56 |
} |
|
66 |
item.setEnabled(action.isAvailable(this.item, this.seleteds)); |
|
67 |
if (!action.getGroup().equals(group)) { |
|
68 |
if (group != null) { |
|
69 |
this.addSeparator(); |
|
70 |
} |
|
71 |
group = action.getGroup(); |
|
72 |
} |
|
73 |
this.add(item); |
|
57 | 74 |
|
75 |
} |
|
76 |
} |
|
77 |
this.actions = actions; |
|
78 |
} |
|
58 | 79 |
|
59 |
public boolean hasActions() { |
|
60 |
return actions!=null || actions.size()>0; |
|
61 |
} |
|
62 |
|
|
63 |
private class MenuItem extends JMenuItem implements ActionListener{ |
|
64 |
/** |
|
80 |
public boolean hasActions() { |
|
81 |
return actions != null || actions.size() > 0; |
|
82 |
} |
|
83 |
|
|
84 |
private class MenuItem extends JMenuItem implements ActionListener { |
|
85 |
|
|
86 |
/** |
|
65 | 87 |
* |
66 | 88 |
*/ |
67 |
private static final long serialVersionUID = -752624469241001299L; |
|
68 |
private DocumentAction action; |
|
69 |
|
|
70 |
public MenuItem(String text,DocumentAction action) { |
|
71 |
super(text); |
|
72 |
this.action = action; |
|
73 |
String tip = this.action.getDescription(); |
|
74 |
if (tip != null && tip.length() > 0) { |
|
75 |
this.setToolTipText(tip); |
|
76 |
} |
|
77 |
this.addActionListener(this); |
|
78 |
} |
|
89 |
private static final long serialVersionUID = -752624469241001299L; |
|
90 |
private DocumentAction action; |
|
79 | 91 |
|
80 |
public void actionPerformed(ActionEvent e) { |
|
81 |
this.action.execute(DocumentContextMenu.this.item, DocumentContextMenu.this.seleteds); |
|
82 |
} |
|
83 |
} |
|
92 |
public MenuItem(String text, DocumentAction action) { |
|
93 |
super(text); |
|
94 |
this.action = action; |
|
95 |
String tip = this.action.getDescription(); |
|
96 |
if (tip != null && tip.length() > 0) { |
|
97 |
this.setToolTipText(tip); |
|
98 |
} |
|
99 |
this.addActionListener(this); |
|
100 |
} |
|
84 | 101 |
|
102 |
public void actionPerformed(ActionEvent e) { |
|
103 |
this.action.execute(DocumentContextMenu.this.item, |
|
104 |
DocumentContextMenu.this.seleteds); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
85 | 108 |
} |
86 |
|
Also available in: Unified diff