svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / EditionLocator.java @ 39591
History | View | Annotate | Download (3.65 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.List; |
5 |
import java.util.Map; |
6 |
|
7 |
import org.gvsig.app.project.Project; |
8 |
import org.gvsig.app.project.ProjectManager; |
9 |
import org.gvsig.app.project.documents.Document; |
10 |
import org.gvsig.app.project.documents.view.ViewDocument; |
11 |
import org.gvsig.editing.gui.cad.CADToolAdapter; |
12 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
13 |
|
14 |
public class EditionLocator { |
15 |
|
16 |
private static CADToolAdapter adapter=null; |
17 |
private static Map<ViewDocument,CADToolAdapter> adapters=new HashMap<ViewDocument,CADToolAdapter>(); |
18 |
|
19 |
/**
|
20 |
* Gets the CADToolAdapter of the view where the layer is
|
21 |
* contained or null if the layer is not found
|
22 |
* in any view
|
23 |
*
|
24 |
* @param layer
|
25 |
* @return CADToolAdapter of the layer
|
26 |
*/
|
27 |
public static CADToolAdapter getCADToolAdapter(FLayer layer) { |
28 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
29 |
List<Document> docs = project.getDocuments(); |
30 |
for( int i=0; i<docs.size(); i++ ) { |
31 |
Document doc = docs.get(i);
|
32 |
if( doc instanceof ViewDocument ) { |
33 |
ViewDocument view = (ViewDocument)doc; |
34 |
if (view.getMapContext() == layer.getMapContext() ) {
|
35 |
CADToolAdapter cta = adapters.get(doc); |
36 |
if ( cta == null ) { |
37 |
cta = new CADToolAdapter();
|
38 |
adapters.put(view,cta); |
39 |
} |
40 |
return cta;
|
41 |
} |
42 |
} |
43 |
} |
44 |
return null; |
45 |
} |
46 |
|
47 |
/**
|
48 |
* Gets the CADToolAdapter of the view
|
49 |
* or null if the view not found in the current project
|
50 |
*
|
51 |
* @return CADToolAdapter of the view
|
52 |
*/
|
53 |
public static CADToolAdapter getCADToolAdapter(ViewDocument view) { |
54 |
CADToolAdapter cta = adapters.get(view); |
55 |
if (cta == null) { |
56 |
cta = new CADToolAdapter();
|
57 |
adapters.put(view, cta); |
58 |
} |
59 |
return cta;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Gets the CADToolAdapter of the currently active view
|
64 |
* or the CADToolAdapter of the view that was active more
|
65 |
* recently (if there is not an active view)
|
66 |
* or null if there never was an active view
|
67 |
*
|
68 |
* @return CADToolAdapter of current view
|
69 |
*/
|
70 |
public static CADToolAdapter getCADToolAdapter() { |
71 |
ViewDocument view = (ViewDocument) ProjectManager.getInstance().getCurrentProject().getActiveDocument(ViewDocument.class); |
72 |
if( view != null ) { |
73 |
adapter = adapters.get(view); |
74 |
if( adapter==null ) { |
75 |
adapter = new CADToolAdapter();
|
76 |
adapters.put(view, adapter); |
77 |
} |
78 |
return adapter;
|
79 |
} |
80 |
return adapter;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
*
|
85 |
* Gets the edition manager of the currently active view
|
86 |
* or the edition manager of the view that was active more
|
87 |
* recently (if there is not an active view)
|
88 |
* or null if there never was an active view.
|
89 |
*
|
90 |
* @return
|
91 |
*/
|
92 |
public static IEditionManager getEditionManager() { |
93 |
CADToolAdapter cta=getCADToolAdapter(); |
94 |
if (cta == null) { |
95 |
return null; |
96 |
} else {
|
97 |
return cta.getEditionManager();
|
98 |
} |
99 |
|
100 |
} |
101 |
|
102 |
|
103 |
|
104 |
/**
|
105 |
* Gets the EditionManager of the view where the layer is
|
106 |
* contained or null if the layer is not found
|
107 |
* in any view
|
108 |
*
|
109 |
* @param layer
|
110 |
* @return
|
111 |
*/
|
112 |
public static IEditionManager getEditionManager(FLayer layer) { |
113 |
CADToolAdapter cta=getCADToolAdapter(layer); |
114 |
if (cta == null) { |
115 |
return null; |
116 |
} else {
|
117 |
return cta.getEditionManager();
|
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Gets the EditionManager of the ViewDocument or null if the view is not found
|
124 |
* in the project
|
125 |
*
|
126 |
* @param viewDocument
|
127 |
* @return
|
128 |
*/
|
129 |
public static IEditionManager getEditionManager(ViewDocument view) { |
130 |
CADToolAdapter cta=getCADToolAdapter(view); |
131 |
if (cta == null) { |
132 |
return null; |
133 |
} else {
|
134 |
return cta.getEditionManager();
|
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
} |