svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / layout / mapbox / panel / menu / AddColumnMapBoxMenuEntry.java @ 1714
History | View | Annotate | Download (3.53 KB)
1 | 5 | jldominguez | /* 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 | 1714 | fdiaz | package org.gvsig.layout.mapbox.panel.menu; |
23 | 5 | jldominguez | |
24 | 1714 | fdiaz | import java.util.List; |
25 | 5 | jldominguez | import org.gvsig.andami.PluginServices; |
26 | import org.gvsig.app.project.documents.layout.LayoutContext; |
||
27 | 1714 | fdiaz | import org.gvsig.app.project.documents.layout.contextmenu.gui.*; |
28 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
29 | 1714 | fdiaz | import org.gvsig.layout.mapbox.fframe.FFrameMapBox; |
30 | import org.gvsig.layout.mapbox.model.Cell; |
||
31 | import org.gvsig.tools.lang.CloneableUtils; |
||
32 | 5 | jldominguez | |
33 | /**
|
||
34 | * Copia el FFrame seleccionado.
|
||
35 | 1714 | fdiaz | *
|
36 | * @author gvSIG team
|
||
37 | 5 | jldominguez | */
|
38 | 1714 | fdiaz | public class AddColumnMapBoxMenuEntry extends AbstractLayoutContextMenuAction { |
39 | 5 | jldominguez | |
40 | 1714 | fdiaz | @Override
|
41 | 5 | jldominguez | public String getGroup() { |
42 | 1714 | fdiaz | return "mapbox"; |
43 | 5 | jldominguez | } |
44 | |||
45 | 1714 | fdiaz | @Override
|
46 | 5 | jldominguez | public int getGroupOrder() { |
47 | 1714 | fdiaz | return 5; |
48 | 5 | jldominguez | } |
49 | |||
50 | 1714 | fdiaz | @Override
|
51 | 5 | jldominguez | public int getOrder() { |
52 | 1714 | fdiaz | return 5; |
53 | 5 | jldominguez | } |
54 | |||
55 | 1714 | fdiaz | @Override
|
56 | 5 | jldominguez | public String getText() { |
57 | 1714 | fdiaz | return PluginServices.getText(this, "_Add_column"); |
58 | 5 | jldominguez | } |
59 | |||
60 | 1714 | fdiaz | @Override
|
61 | 5 | jldominguez | public boolean isEnabled(LayoutContext layoutContext, |
62 | IFFrame[] selectedFrames) {
|
||
63 | 1714 | fdiaz | if (selectedFrames.length != 1) { |
64 | return false; |
||
65 | } |
||
66 | for (IFFrame selectedFrame : selectedFrames) {
|
||
67 | if (selectedFrame instanceof FFrameMapBox) { |
||
68 | FFrameMapBox frame = (FFrameMapBox) selectedFrame; |
||
69 | List<Cell> selectedCells = frame.getSelectedCells();
|
||
70 | return selectedCells.size() == 1; |
||
71 | } |
||
72 | } |
||
73 | return false; |
||
74 | 5 | jldominguez | } |
75 | |||
76 | 1714 | fdiaz | @Override
|
77 | 5 | jldominguez | public boolean isVisible(LayoutContext layoutContext, |
78 | IFFrame[] selectedFrames) {
|
||
79 | 1714 | fdiaz | for (IFFrame selectedFrame : selectedFrames) {
|
80 | if (selectedFrame instanceof FFrameMapBox) { |
||
81 | return true; |
||
82 | } |
||
83 | } |
||
84 | 5 | jldominguez | return false; |
85 | } |
||
86 | |||
87 | 1714 | fdiaz | @Override
|
88 | 5 | jldominguez | public void execute(LayoutContext layoutContext, IFFrame[] selectedFrames) { |
89 | 1714 | fdiaz | if (selectedFrames.length != 1) { |
90 | return;
|
||
91 | 5 | jldominguez | } |
92 | 1714 | fdiaz | IFFrame selectedFrame = selectedFrames[0];
|
93 | |||
94 | if (selectedFrame instanceof FFrameMapBox) { |
||
95 | FFrameMapBox frame = (FFrameMapBox) selectedFrame; |
||
96 | if (frame.getSelectedCells().size() != 1) { |
||
97 | return;
|
||
98 | } |
||
99 | FFrameMapBox newFrame = (FFrameMapBox) CloneableUtils.cloneQuietly(frame); |
||
100 | List<Cell> selectedCells = newFrame.getSelectedCells();
|
||
101 | if (selectedCells.size() == 1) { |
||
102 | newFrame.getModel().addColumn(selectedCells.get(0));
|
||
103 | newFrame.getSelection().clear(); |
||
104 | layoutContext.fullRefresh(); |
||
105 | layoutContext.getFrameCommandsRecord().update(frame, newFrame); |
||
106 | layoutContext.updateFFrames(); |
||
107 | } |
||
108 | } |
||
109 | 5 | jldominguez | } |
110 | } |