svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / EditionLocator.java @ 40557
History | View | Annotate | Download (4.58 KB)
1 | 40557 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.editing; |
25 | |||
26 | import java.util.HashMap; |
||
27 | import java.util.List; |
||
28 | import java.util.Map; |
||
29 | |||
30 | import org.gvsig.app.project.Project; |
||
31 | import org.gvsig.app.project.ProjectManager; |
||
32 | import org.gvsig.app.project.documents.Document; |
||
33 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
34 | import org.gvsig.editing.gui.cad.CADToolAdapter; |
||
35 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
36 | |||
37 | public class EditionLocator { |
||
38 | |||
39 | private static CADToolAdapter adapter=null; |
||
40 | private static Map<ViewDocument,CADToolAdapter> adapters=new HashMap<ViewDocument,CADToolAdapter>(); |
||
41 | |||
42 | /**
|
||
43 | * Gets the CADToolAdapter of the view where the layer is
|
||
44 | * contained or null if the layer is not found
|
||
45 | * in any view
|
||
46 | *
|
||
47 | * @param layer
|
||
48 | * @return CADToolAdapter of the layer
|
||
49 | */
|
||
50 | public static CADToolAdapter getCADToolAdapter(FLayer layer) { |
||
51 | Project project = ProjectManager.getInstance().getCurrentProject(); |
||
52 | List<Document> docs = project.getDocuments(); |
||
53 | for( int i=0; i<docs.size(); i++ ) { |
||
54 | Document doc = docs.get(i);
|
||
55 | if( doc instanceof ViewDocument ) { |
||
56 | ViewDocument view = (ViewDocument)doc; |
||
57 | if (view.getMapContext() == layer.getMapContext() ) {
|
||
58 | CADToolAdapter cta = adapters.get(doc); |
||
59 | if ( cta == null ) { |
||
60 | cta = new CADToolAdapter();
|
||
61 | adapters.put(view,cta); |
||
62 | } |
||
63 | return cta;
|
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | return null; |
||
68 | } |
||
69 | |||
70 | /**
|
||
71 | * Gets the CADToolAdapter of the view
|
||
72 | * or null if the view not found in the current project
|
||
73 | *
|
||
74 | * @return CADToolAdapter of the view
|
||
75 | */
|
||
76 | public static CADToolAdapter getCADToolAdapter(ViewDocument view) { |
||
77 | CADToolAdapter cta = adapters.get(view); |
||
78 | if (cta == null) { |
||
79 | cta = new CADToolAdapter();
|
||
80 | adapters.put(view, cta); |
||
81 | } |
||
82 | return cta;
|
||
83 | } |
||
84 | |||
85 | /**
|
||
86 | * Gets the CADToolAdapter of the currently active view
|
||
87 | * or the CADToolAdapter of the view that was active more
|
||
88 | * recently (if there is not an active view)
|
||
89 | * or null if there never was an active view
|
||
90 | *
|
||
91 | * @return CADToolAdapter of current view
|
||
92 | */
|
||
93 | public static CADToolAdapter getCADToolAdapter() { |
||
94 | ViewDocument view = (ViewDocument) ProjectManager.getInstance().getCurrentProject().getActiveDocument(ViewDocument.class); |
||
95 | if( view != null ) { |
||
96 | adapter = adapters.get(view); |
||
97 | if( adapter==null ) { |
||
98 | adapter = new CADToolAdapter();
|
||
99 | adapters.put(view, adapter); |
||
100 | } |
||
101 | return adapter;
|
||
102 | } |
||
103 | return adapter;
|
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | *
|
||
108 | * Gets the edition manager of the currently active view
|
||
109 | * or the edition manager of the view that was active more
|
||
110 | * recently (if there is not an active view)
|
||
111 | * or null if there never was an active view.
|
||
112 | *
|
||
113 | * @return
|
||
114 | */
|
||
115 | public static IEditionManager getEditionManager() { |
||
116 | CADToolAdapter cta=getCADToolAdapter(); |
||
117 | if (cta == null) { |
||
118 | return null; |
||
119 | } else {
|
||
120 | return cta.getEditionManager();
|
||
121 | } |
||
122 | |||
123 | } |
||
124 | |||
125 | |||
126 | |||
127 | /**
|
||
128 | * Gets the EditionManager of the view where the layer is
|
||
129 | * contained or null if the layer is not found
|
||
130 | * in any view
|
||
131 | *
|
||
132 | * @param layer
|
||
133 | * @return
|
||
134 | */
|
||
135 | public static IEditionManager getEditionManager(FLayer layer) { |
||
136 | CADToolAdapter cta=getCADToolAdapter(layer); |
||
137 | if (cta == null) { |
||
138 | return null; |
||
139 | } else {
|
||
140 | return cta.getEditionManager();
|
||
141 | } |
||
142 | |||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * Gets the EditionManager of the ViewDocument or null if the view is not found
|
||
147 | * in the project
|
||
148 | *
|
||
149 | * @param viewDocument
|
||
150 | * @return
|
||
151 | */
|
||
152 | public static IEditionManager getEditionManager(ViewDocument view) { |
||
153 | CADToolAdapter cta=getCADToolAdapter(view); |
||
154 | if (cta == null) { |
||
155 | return null; |
||
156 | } else {
|
||
157 | return cta.getEditionManager();
|
||
158 | } |
||
159 | |||
160 | } |
||
161 | |||
162 | } |