gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.app / org.gvsig.vcsgis.app.mainplugin / src / main / java / org / gvsig / vcsgis / app / VCSGisSwingServicesImpl.java @ 2822
History | View | Annotate | Download (4.24 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.vcsgis.app; |
7 |
|
8 |
import java.util.List; |
9 |
import javax.swing.ComboBoxModel; |
10 |
import javax.swing.DefaultComboBoxModel; |
11 |
import javax.swing.DefaultListModel; |
12 |
import javax.swing.ListModel; |
13 |
import javax.swing.tree.TreeModel; |
14 |
import org.apache.commons.lang.StringUtils; |
15 |
import org.gvsig.app.ApplicationLocator; |
16 |
import org.gvsig.app.ApplicationManager; |
17 |
import org.gvsig.app.project.Project; |
18 |
import org.gvsig.app.project.documents.Document; |
19 |
import org.gvsig.app.project.documents.DocumentManager; |
20 |
import org.gvsig.app.project.documents.table.TableDocument; |
21 |
import org.gvsig.app.project.documents.table.TableManager; |
22 |
import org.gvsig.app.project.documents.view.ViewDocument; |
23 |
import org.gvsig.app.project.documents.view.ViewManager; |
24 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
25 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
26 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
27 |
import org.gvsig.tools.ToolsLocator; |
28 |
import org.gvsig.tools.i18n.I18nManager; |
29 |
import org.gvsig.tools.util.LabeledValue; |
30 |
import org.gvsig.tools.util.LabeledValueImpl; |
31 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
32 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author fdiaz
|
37 |
*/
|
38 |
public class VCSGisSwingServicesImpl implements VCSGisSwingServices { |
39 |
|
40 |
@Override
|
41 |
public TreeModel getFeatureStoresTreeModel() { |
42 |
return new FeatureStoresTreeModel(); |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public ListModel getFeatureStoresListModel() { |
47 |
DefaultListModel<FeatureStore> model = new DefaultListModel(); |
48 |
|
49 |
ApplicationManager appManager = ApplicationLocator.getApplicationManager(); |
50 |
Project project = appManager.getCurrentProject(); |
51 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
52 |
for (Document document : tables) { |
53 |
TableDocument table = (TableDocument) document; |
54 |
model.addElement(table.getFeatureStore()); |
55 |
} |
56 |
|
57 |
return model;
|
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void addTableToProject(VCSGisWorkspace ws, FeatureStore store) { |
62 |
ApplicationManager appManager = ApplicationLocator.getApplicationManager(); |
63 |
|
64 |
DocumentManager tableManager = appManager.getProjectManager().getDocumentManager( |
65 |
TableManager.TYPENAME |
66 |
); |
67 |
|
68 |
Project project = appManager.getCurrentProject(); |
69 |
TableDocument tableDoc = (TableDocument) tableManager.createDocument(); |
70 |
|
71 |
tableDoc.setName(ws.getLabel()+" - " + store.getName());
|
72 |
tableDoc.setStore(store); |
73 |
project.addDocument(tableDoc); |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public ComboBoxModel getViewDocumentsComboBoxModel() { |
78 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
79 |
DefaultComboBoxModel<LabeledValue> model = new DefaultComboBoxModel(); |
80 |
model.addElement(new LabeledValueImpl(i18n.getTranslation("_Select_a_view"), null)); |
81 |
ApplicationManager appManager = ApplicationLocator.getApplicationManager(); |
82 |
Project project = appManager.getCurrentProject(); |
83 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
84 |
for (Document document : views) { |
85 |
ViewDocument view = (ViewDocument) document; |
86 |
model.addElement(new LabeledValueImpl(view.getName(), view));
|
87 |
} |
88 |
return model;
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void addLayerToView(FeatureStore store, LabeledValue labeledView) { |
93 |
addLayerToView(store, labeledView, null);
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public void addLayerToView(FeatureStore store, LabeledValue labeledView, String name) { |
98 |
try {
|
99 |
if (labeledView.getValue() == null){ |
100 |
return;
|
101 |
} |
102 |
ViewDocument view = (ViewDocument) labeledView.getValue(); |
103 |
String layerName = name;
|
104 |
if(StringUtils.isBlank(layerName)){
|
105 |
layerName = store.getName(); |
106 |
} |
107 |
FLayer layer = MapContextLocator.getMapContextManager().createLayer(layerName, store); |
108 |
view.getMapContext().getLayers().add(layer); |
109 |
} catch (Exception ex) { |
110 |
throw new RuntimeException("Can't add layer to view.", ex); //FIXME |
111 |
} |
112 |
} |
113 |
|
114 |
} |