01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.internal.impl;
16:
17: import java.io.IOException;
18:
19: import net.refractions.udig.catalog.IGeoResourceInfo;
20: import net.refractions.udig.project.interceptor.LayerInterceptor;
21: import net.refractions.udig.project.internal.Layer;
22: import net.refractions.udig.ui.ProgressManager;
23:
24: /**
25: * Sets the name of a newly created layer.
26: *
27: * @author Jesse
28: * @since 1.1.0
29: */
30: public class SetLayerNameInterceptor implements LayerInterceptor {
31:
32: public void run(Layer layer) {
33: try {
34: IGeoResourceInfo info = layer.getGeoResource().getInfo(
35: ProgressManager.instance().get());
36: nameLayer(info, layer);
37: } catch (IOException e) {
38: //shouldn't happen
39: throw (RuntimeException) new RuntimeException()
40: .initCause(e);
41: }
42: }
43:
44: private void nameLayer(IGeoResourceInfo info, Layer layer) {
45: String label = info.getTitle(); // may be empty?
46: if (label == null || label.trim().length() == 0) {
47: label = info.getName(); // really should not be empty?
48: }
49: if (label == null || label.trim().length() == 0) {
50: label = "newLayer"; // really should not be empty?
51: }
52: layer.setName(label); // XXX: Is this a user provided label?
53: }
54:
55: }
|