001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.viewer;
028:
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.lang.reflect.Modifier;
032: import java.util.ArrayList;
033: import java.util.List;
034:
035: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
036: import fr.ign.cogit.geoxygene.datatools.Metadata;
037: import fr.ign.cogit.geoxygene.feature.FT_Feature;
038: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
039:
040: /**
041: * This class defines actions for access to GeOxygene repository (menu bar and toolbar).
042: *
043: * @author Thierry Badard & Arnaud Braun
044: * @version 1.0
045: *
046: */
047:
048: class GeOxygeneViewerOpenGeOxygeneAction implements ActionListener {
049:
050: private ObjectViewerInterface objectViewerInterface;
051: private Geodatabase db;
052:
053: public GeOxygeneViewerOpenGeOxygeneAction(
054: ObjectViewerInterface objViewerInterface, Geodatabase data) {
055: this .objectViewerInterface = objViewerInterface;
056: this .db = data;
057: }
058:
059: public void actionPerformed(ActionEvent e) {
060: String user = null;
061: try {
062: user = db.getConnection().getMetaData().getUserName();
063: } catch (Exception exc) {
064: exc.printStackTrace();
065: }
066: System.out.println(user + " est le plus beau !");
067: List classList = new ArrayList();
068: for (int i = 0; i < db.getMetadata().size(); i++) {
069: Metadata md = (Metadata) db.getMetadata().get(i);
070: Class theClass = md.getJavaClass();
071: if (FT_Feature.class.isAssignableFrom(theClass)
072: && !Modifier.isAbstract(theClass.getModifiers()))
073: classList.add(theClass.getName());
074: }
075:
076: System.out.println("Selecting geographic classes ...");
077: GeOxygeneFilter geOxyFilter = new GeOxygeneFilter(classList
078: .toArray(), user);
079: String[] selectedClasses = geOxyFilter
080: .showDialog(objectViewerInterface);
081:
082: for (int i = 0; i < selectedClasses.length; i++) {
083: String themeName = selectedClasses[i]
084: .substring(selectedClasses[i].lastIndexOf(".") + 1);
085: Class theClass = null;
086: try {
087: theClass = Class.forName(selectedClasses[i]);
088: } catch (Exception exp) {
089: System.out.println(exp.getMessage() + " : "
090: + selectedClasses[i]);
091: }
092: if (theClass != null) {
093: System.out.println("Loading " + selectedClasses[i]
094: + " ... please wait ...");
095: FT_FeatureCollection coll = db
096: .loadAllFeatures(theClass);
097: System.out
098: .println(" Loading finished. Displaying theme in viewer ...");
099: objectViewerInterface.addAFeatureCollectionTheme(coll,
100: themeName);
101: }
102: }
103: }
104:
105: }
|