gvsig-projects-pool / org.gvsig.topology / trunk / org.gvsig.topology / org.gvsig.topology.app / org.gvsig.topology.app.mainplugin / src / main / java / org / gvsig / topology / app / mainplugin / DataSetsTreeModel.java @ 727
History | View | Annotate | Download (5 KB)
1 | 688 | 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 | package org.gvsig.topology.app.mainplugin; |
||
25 | |||
26 | 727 | jjdelcerro | import javax.swing.ImageIcon; |
27 | 688 | jjdelcerro | import javax.swing.event.TreeModelListener; |
28 | import javax.swing.tree.TreeModel; |
||
29 | import javax.swing.tree.TreePath; |
||
30 | 727 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
31 | 688 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
32 | 727 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
33 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
34 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
35 | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
||
36 | 688 | jjdelcerro | import org.gvsig.fmap.mapcontrol.CompoundLayersTreeModel; |
37 | import org.gvsig.fmap.mapcontrol.MapControlLocator; |
||
38 | 722 | jjdelcerro | import org.gvsig.tools.swing.api.ListElement; |
39 | 727 | jjdelcerro | import org.gvsig.topology.lib.api.TopologyDataSet; |
40 | 688 | jjdelcerro | import org.gvsig.topology.lib.api.TopologyLocator; |
41 | import org.gvsig.topology.swing.api.TopologySwingServices; |
||
42 | |||
43 | /**
|
||
44 | *
|
||
45 | * @author jjdelcerro
|
||
46 | */
|
||
47 | public class DataSetsTreeModel implements TreeModel { |
||
48 | |||
49 | private final ViewDocument view; |
||
50 | private final CompoundLayersTreeModel deletaged; |
||
51 | private final TopologySwingServices services; |
||
52 | 722 | jjdelcerro | private final ListElement<Object> root; |
53 | 688 | jjdelcerro | |
54 | public DataSetsTreeModel(TopologySwingServices services, ViewDocument view) {
|
||
55 | this.services = services;
|
||
56 | this.view = view;
|
||
57 | CompoundLayersTreeModel model = (CompoundLayersTreeModel) MapControlLocator.getMapControlManager().createCompoundLayersTreeModel(); |
||
58 | model.addLayers(view.getMapContext().getLayers()); |
||
59 | this.deletaged = model;
|
||
60 | 722 | jjdelcerro | this.root = new ListElement<>("Project", this.deletaged.getRoot()); |
61 | |||
62 | 688 | jjdelcerro | } |
63 | |||
64 | 722 | jjdelcerro | private Object getNode(Object value) { |
65 | if( value instanceof ListElement ) { |
||
66 | return ((ListElement) value).getValue();
|
||
67 | } |
||
68 | return value;
|
||
69 | } |
||
70 | |||
71 | 688 | jjdelcerro | @Override
|
72 | public Object getRoot() { |
||
73 | 722 | jjdelcerro | return this.root; |
74 | 688 | jjdelcerro | } |
75 | |||
76 | @Override
|
||
77 | public Object getChild(Object parent, int index) { |
||
78 | 722 | jjdelcerro | parent = this.getNode(parent);
|
79 | 688 | jjdelcerro | Object x = this.deletaged.getChild(parent, index); |
80 | 727 | jjdelcerro | if( x instanceof SingleLayer ) { |
81 | SingleLayer layer = (SingleLayer)x; |
||
82 | DataStore store = layer.getDataStore(); |
||
83 | 688 | jjdelcerro | x = TopologyLocator.getTopologyManager().createDataSet( |
84 | layer.getName(), |
||
85 | store |
||
86 | ); |
||
87 | } |
||
88 | return x;
|
||
89 | } |
||
90 | |||
91 | @Override
|
||
92 | public int getChildCount(Object parent) { |
||
93 | 722 | jjdelcerro | parent = this.getNode(parent);
|
94 | 688 | jjdelcerro | return this.deletaged.getChildCount(parent); |
95 | } |
||
96 | |||
97 | @Override
|
||
98 | public boolean isLeaf(Object node) { |
||
99 | 722 | jjdelcerro | node = this.getNode(node);
|
100 | 688 | jjdelcerro | return this.deletaged.isLeaf(node); |
101 | } |
||
102 | |||
103 | @Override
|
||
104 | public void valueForPathChanged(TreePath path, Object newValue) { |
||
105 | this.deletaged.valueForPathChanged(path, newValue);
|
||
106 | } |
||
107 | |||
108 | @Override
|
||
109 | public int getIndexOfChild(Object parent, Object child) { |
||
110 | 722 | jjdelcerro | parent = this.getNode(parent);
|
111 | 688 | jjdelcerro | return this.deletaged.getIndexOfChild(parent, child); |
112 | } |
||
113 | |||
114 | @Override
|
||
115 | public void addTreeModelListener(TreeModelListener l) { |
||
116 | this.deletaged.addTreeModelListener(l);
|
||
117 | } |
||
118 | |||
119 | @Override
|
||
120 | public void removeTreeModelListener(TreeModelListener l) { |
||
121 | this.deletaged.removeTreeModelListener(l);
|
||
122 | } |
||
123 | 727 | jjdelcerro | |
124 | public ImageIcon getTreeIcon(Object item) { |
||
125 | if( this.getRoot()==item ) { |
||
126 | return IconThemeHelper.getImageIcon("topology-tree-project"); |
||
127 | } |
||
128 | if (item instanceof ListElement) { |
||
129 | item = ((ListElement) item).getValue(); |
||
130 | } |
||
131 | if( this.view.getMapContext().getLayers()==item ) { |
||
132 | return IconThemeHelper.getImageIcon("document-view-tree-icon"); |
||
133 | } |
||
134 | if (item instanceof TopologyDataSet) { |
||
135 | DataStore store = ((TopologyDataSet)item).getStore(); |
||
136 | String iconName = MapContextLocator.getMapContextManager().getIconLayer(store);
|
||
137 | return IconThemeHelper.getImageIcon(iconName);
|
||
138 | } |
||
139 | if (item instanceof FLayer) { |
||
140 | String iconName = ((FLayer) item).getTocImageIcon();
|
||
141 | return IconThemeHelper.getImageIcon(iconName);
|
||
142 | } |
||
143 | return IconThemeHelper.getImageIcon("topology-tree-folder"); |
||
144 | } |
||
145 | 688 | jjdelcerro | |
146 | } |