001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.ui.internal.property.pages;
016:
017: import java.io.IOException;
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import net.refractions.udig.project.internal.Map;
022: import net.refractions.udig.project.ui.internal.Messages;
023: import net.refractions.udig.project.ui.summary.SummaryControl;
024: import net.refractions.udig.project.ui.summary.SummaryData;
025: import net.refractions.udig.ui.ProgressManager;
026:
027: import org.eclipse.jface.viewers.ICellModifier;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Control;
030: import org.eclipse.swt.widgets.TreeItem;
031: import org.eclipse.ui.IWorkbenchPropertyPage;
032: import org.eclipse.ui.dialogs.PropertyPage;
033:
034: import com.vividsolutions.jts.geom.Envelope;
035:
036: /**
037: * Shows a summary of the layer
038: *
039: * @author Jesse
040: * @since 1.1.0
041: */
042: public class MapSummary extends PropertyPage implements
043: IWorkbenchPropertyPage {
044: private String newAbstract, newName;
045: private String oldAbstract, oldName;
046: private SummaryData nameData;
047: private SummaryData abstractData;
048: private SummaryControl summaryControl;
049:
050: @Override
051: protected Control createContents(Composite parent) {
052: final Map map = (Map) getElement();
053: Envelope bounds;
054: try {
055: bounds = map.getBounds(ProgressManager.instance().get());
056: } catch (IOException e) {
057: bounds = null;
058: }
059:
060: final List<SummaryData> data = new ArrayList<SummaryData>();
061:
062: String name = map.getName();
063: nameData = new SummaryData(Messages.LayerSummary_name,
064: name == null ? "" : name); //$NON-NLS-1$
065: nameData.setModifier(new NameModifier());
066: data.add(nameData);
067: newName = oldName = nameData.getInfo();
068:
069: String abstract1 = map.getAbstract();
070: abstractData = new SummaryData(Messages.MapSummary_abstract,
071: abstract1 == null ? "" : abstract1); //$NON-NLS-1$
072: abstractData.setModifier(new AbstractModifier());
073: data.add(abstractData);
074: newAbstract = oldAbstract = abstractData.getInfo();
075:
076: data
077: .add(new SummaryData(Messages.LayerSummary_id, map
078: .getID()));
079: data.add(new SummaryData(Messages.MapSummary_mapBounds,
080: bounds == null ? Messages.LayerSummary_unknownBounds
081: : LayerSummary.parseBounds(bounds)));
082: data.add(new SummaryData(Messages.MapSummary_viewportBounds,
083: LayerSummary.parseBounds(map.getViewportModel()
084: .getBounds())));
085:
086: summaryControl = new SummaryControl(data);
087: return summaryControl.createControl(parent);
088: }
089:
090: @Override
091: protected void performApply() {
092: summaryControl.applyEdit();
093: final Map map = (Map) getElement();
094:
095: if (!newName.equals(oldName)) {
096: map.setName(newName);
097: }
098: if (!newAbstract.equals(oldAbstract)) {
099: map.setAbstract(newAbstract);
100: }
101: }
102:
103: @Override
104: public boolean performCancel() {
105: performDefaults();
106: return super .performCancel();
107: }
108:
109: @Override
110: public boolean performOk() {
111: performApply();
112: return super .performOk();
113: }
114:
115: @Override
116: protected void performDefaults() {
117: summaryControl.cancelEdit();
118: final Map map = (Map) getElement();
119: if (!newAbstract.equals(oldAbstract)) {
120: newAbstract = oldAbstract;
121: abstractData.setInfo(oldAbstract);
122: summaryControl.refresh(abstractData);
123: map.setAbstract(oldAbstract);
124: }
125: if (!newName.equals(oldName)) {
126: newName = oldName;
127: nameData.setInfo(oldName);
128: summaryControl.refresh(nameData);
129: map.setName(oldName);
130: }
131: }
132:
133: private class NameModifier implements ICellModifier {
134:
135: public boolean canModify(Object element, String property) {
136: if (element == nameData)
137: return true;
138: return false;
139: }
140:
141: public Object getValue(Object element, String property) {
142:
143: if (!newName.equals(oldName))
144: return newName;
145: return ((SummaryData) element).getInfo();
146: }
147:
148: public void modify(Object element, String property, Object value) {
149: if (((TreeItem) element).getData() == nameData) {
150: newName = (String) value;
151: nameData.setInfo(newName);
152: summaryControl.refresh(nameData);
153: }
154: }
155: }
156:
157: private class AbstractModifier implements ICellModifier {
158:
159: public boolean canModify(Object element, String property) {
160: if (element == abstractData)
161: return true;
162: return false;
163: }
164:
165: public Object getValue(Object element, String property) {
166: if (!newAbstract.equals(oldAbstract))
167: return newAbstract;
168:
169: return ((SummaryData) element).getInfo();
170: }
171:
172: public void modify(Object element, String property, Object value) {
173: if (((TreeItem) element).getData() == abstractData) {
174: newAbstract = (String) value;
175: nameData.setInfo(newName);
176: summaryControl.refresh(nameData);
177: }
178: }
179: }
180: }
|