示例#1
0
  // pretty much the main method, finds and loads extensions from
  // plugin dir
  // and
  // plugins/extensions defined in workbench properties (developers use this)
  public void load() throws Exception {
    // load plugins from workbench-properties
    loadPlugIns(context.getWorkbench().getProperties());

    long start;

    // Find the configurations right away so they get reported to the splash
    // screen ASAP. [Jon Aquino]
    if (plugInDirectory != null) {
      start = secondsSince(0);
      configurations.addAll(findConfigurations(plugInDirectory));
      System.out.println("Finding all OJ extensions took " + secondsSinceString(start) + "s");
    }

    configurations.addAll(
        findConfigurations(context.getWorkbench().getProperties().getConfigurationClasses()));

    start = secondsSince(0);
    loadConfigurations();
    System.out.println("Loading all OJ extensions took " + secondsSinceString(start) + "s");

    // enable autoseparating in installer for plugins possibly installed later on
    FeatureInstaller.getInstance().setSeparatingEnabled(true);
    // for performance reasons we separate menu entries once
    // after all plugins/extensions were installed
    FeatureInstaller.getInstance().updateSeparatorsInAllMenus();
  }
示例#2
0
 private void loadConfigurations() {
   PlugInContext pc = context.createPlugInContext();
   for (Iterator i = configurations.iterator(); i.hasNext(); ) {
     Configuration configuration = (Configuration) i.next();
     monitor.report(LOADING + " " + name(configuration) + " " + version(configuration));
     long start = secondsSince(0);
     try {
       configuration.configure(pc);
       System.out.println(
           "Loading "
               + name(configuration)
               + " "
               + version(configuration)
               + " took "
               + secondsSinceString(start)
               + "s");
     } catch (Throwable e) {
       context.getErrorHandler().handleThrowable(e);
       context
           .getWorkbench()
           .getFrame()
           .log(configuration.getClass().getName() + " " + NOT_INITIALIZED, this.getClass());
     }
   }
 }
 public static void fix(WorkbenchContext context) {
   for (Iterator i = context.getFeatureTextWriterRegistry().iterator(); i.hasNext(); ) {
     AbstractFeatureTextWriter writer = (AbstractFeatureTextWriter) i.next();
     if (writer.getShortDescription().equals("CL")) {
       i.remove();
     }
   }
   context
       .getFeatureTextWriterRegistry()
       .register(
           new AbstractFeatureTextWriter(false, "CL", "Coordinate List") {
             public String write(Feature feature) {
               StringBuffer s = new StringBuffer();
               String className =
                   StringUtil.classNameWithoutQualifiers(
                       feature.getGeometry().getClass().getName());
               s.append(className + "\n");
               Coordinate[] coordinates = feature.getGeometry().getCoordinates();
               for (int i = 0; i < coordinates.length; i++) {
                 s.append("[" + Fmt.fmt(i, 10) + "] ");
                 s.append(
                     coordinates[i].x
                         + ", "
                         + coordinates[i].y
                         + (Double.isNaN(coordinates[i].z) ? "" : ", " + coordinates[i].z)
                         + "\n");
               }
               return s.toString().trim();
             }
           });
 }
示例#4
0
  /**
   * Añade un DataSourceQueryChooser (dialogo de selección de orígenes de datos) al sistema.
   *
   * @param reader
   * @param description
   * @param readerWriterDataSourceClass
   */
  private void addFileDataSourceQueryChoosers(
      JUMPReader reader,
      WorkbenchContext context,
      final String description,
      Class readerWriterDataSourceClass) {

    DataSourceQueryChooserManager.get(context.getBlackboard())
        .addLoadDataSourceQueryChooser(
            new GeopistaLoadDxfQueryChooser(
                readerWriterDataSourceClass,
                description,
                extensions(readerWriterDataSourceClass),
                context) {

              protected void addFileFilters(JFileChooser chooser) {
                super.addFileFilters(chooser);
                InstallStandardDataSourceQueryChoosersPlugIn.addCompressedFileFilter(
                    description, chooser);
              } // addFileFilters
            })
        .addSaveDataSourceQueryChooser(
            new GeopistaSaveDxfQueryChooser(
                readerWriterDataSourceClass,
                description,
                extensions(readerWriterDataSourceClass),
                context));
  } // addFileDataSourceQueryChoosers
示例#5
0
 public GeopistaMap(WorkbenchContext context) {
   // super();
   setIdMunicipio(AppContext.getIdMunicipio());
   setIdEntidad(AppContext.getIdEntidad());
   //    layerManager.setCoordinateSystem(PredefinedCoordinateSystems.createUTMNorth(30));
   layerManager.addLayerListener((LayerListener) context.getWorkbench());
 }
示例#6
0
 protected FUTURE_OneLayerAttributeTab createAttributeTab(WorkbenchContext context) {
   return new FUTURE_OneLayerAttributeTab(
       new InfoModel(),
       context,
       ((TaskFrameProxy) context.getWorkbench().getFrame().getActiveInternalFrame())
           .getTaskFrame(),
       context);
 }
  public static final void install(
      ExtensionManagerDialog extensionManager,
      WorkbenchContext workbenchContext,
      ExtensionWrapper ext,
      TaskMonitor monitor)
      throws Exception {

    PlugInManager manager = workbenchContext.getWorkbench().getPlugInManager();

    monitor.report(I18N.get("deejump.pluging.manager.ExtensionHelper.Downloading-resources"));

    File[] files =
        downloadAndSaveResources(
            extensionManager.getExtensionSite(), ext, manager.getPlugInDirectory());

    URLClassLoader classLoader = new URLClassLoader(toURLs(files));

    monitor.report(I18N.get("deejump.pluging.manager.ExtensionHelper.Loading-classes"));

    // list Extension and/or Configuration classes inside the zips/jars
    List extensionClasses = new ArrayList(10);
    for (int i = 0; i < files.length; i++) {
      extensionClasses.addAll(classes(new ZipFile(files[i]), classLoader));
    }

    List configs = new ArrayList();
    for (Iterator iter = extensionClasses.iterator(); iter.hasNext(); ) {
      Class c = (Class) iter.next();
      Configuration configuration = (Configuration) c.newInstance();
      configs.add(configuration);
    }

    monitor.report(I18N.get("deejump.pluging.manager.ExtensionHelper.Loading-extensions"));

    // finally, load configs/extensions
    // this method will call extension.configure(new PlugInContext(context, null, null,
    // null, null)); )
    loadConfigurations(configs, workbenchContext);
  }
示例#8
0
  public static void reportExceptions(
      ArrayList exceptions, DataSourceQuery dataSourceQuery, WorkbenchContext context) {
    context
        .getIWorkbench()
        .getFrame()
        .getOutputFrame()
        .addHeader(
            1,
            exceptions.size()
                + " problem"
                + StringUtil.s(exceptions.size())
                + " loading "
                + dataSourceQuery.toString()
                + "."
                + ((exceptions.size() > 10) ? " First and last five:" : ""));
    context.getIWorkbench().getFrame().getOutputFrame().addText("See View / Log for stack traces");
    context.getIWorkbench().getFrame().getOutputFrame().append("<ul>");

    Collection exceptionsToReport =
        exceptions.size() <= 10
            ? exceptions
            : CollectionUtil.concatenate(
                Arrays.asList(
                    new Collection[] {
                      exceptions.subList(0, 5),
                      exceptions.subList(exceptions.size() - 5, exceptions.size())
                    }));
    for (Iterator j = exceptionsToReport.iterator(); j.hasNext(); ) {
      Exception exception = (Exception) j.next();
      context.getIWorkbench().getGuiComponent().log(StringUtil.stackTrace(exception));
      context.getIWorkbench().getFrame().getOutputFrame().append("<li>");
      context
          .getIWorkbench()
          .getFrame()
          .getOutputFrame()
          .append(GUIUtil.escapeHTML(WorkbenchFrameImpl.toMessage(exception), true, true));
      context.getIWorkbench().getFrame().getOutputFrame().append("</li>");
    }
    context.getIWorkbench().getFrame().getOutputFrame().append("</ul>");
  }
 private Blackboard blackboard() {
   return context.getBlackboard();
 }
示例#10
0
  private void loadPlugIns(WorkbenchProperties props) {
    PlugInContext pc = context.createPlugInContext();
    // List<String> classNames = props.getPlugInClassNames();
    Map<String, Map<String, String>> pluginSettings =
        props.getSettings(new String[] {WorkbenchProperties.KEY_PLUGIN});
    int i = 0;
    for (String className : pluginSettings.keySet()) {
      //        System.out.println(i++ + "/"+ className);
      String initSetting = pluginSettings.get(className).get(WorkbenchProperties.ATTR_INITIALIZE);
      if (initSetting instanceof String && initSetting.equals(WorkbenchProperties.ATTR_VALUE_FALSE))
        continue;

      monitor.report(LOADING + " " + className);

      Class plugInClass = null;
      try {
        long start = secondsSince(0);
        plugInClass = Class.forName(className);
        PlugIn plugIn = (PlugIn) plugInClass.newInstance();
        plugIn.initialize(pc);

        // get plugin's menu settings
        Map<String, Map> menuSettings =
            props.getSettings(
                new String[] {
                  WorkbenchProperties.KEY_PLUGIN, className, WorkbenchProperties.KEY_MENUS
                });

        // interpret menu settings
        for (Map.Entry<String, Map> entry : menuSettings.entrySet()) {

          String menuKey = entry.getKey();
          if (pc.getFeatureInstaller().fetchMenuForKey(menuKey) == null) continue;

          // install me to menu?
          String installSetting =
              props.getSetting(
                  new String[] {
                    WorkbenchProperties.KEY_PLUGIN,
                    className,
                    WorkbenchProperties.KEY_MENUS,
                    menuKey,
                    WorkbenchProperties.ATTR_INSTALL
                  });
          //            String orderSetting = props.getSetting(new String[] {
          //                WorkbenchProperties.KEY_PLUGIN, className,
          //                WorkbenchProperties.KEY_MENUS,
          //                menuKey,
          //                WorkbenchProperties.ATTR_ORDERID});
          // log (order) info
          //            context
          //                .getWorkbench()
          //                .getFrame()
          //                .log(
          //                    "install " + className + " to " + menuKey + " = "
          //                        + installSetting + " with orderid = " + orderSetting);
          // install, or not
          if (installSetting.equals(WorkbenchProperties.ATTR_VALUE_TRUE))
            pc.getFeatureInstaller().addMenuPlugin(menuKey, plugIn);
        }

        // register shortcuts of plugins
        AbstractPlugIn.registerShortcuts(plugIn);

        context
            .getWorkbench()
            .getFrame()
            .log("Loading " + className + " took " + secondsSinceString(start) + "s");

      } catch (Throwable e) {
        context.getErrorHandler().handleThrowable(e);
        context.getWorkbench().getFrame().log(className + " " + NOT_INITIALIZED, this.getClass());
      }
    }
  }
示例#11
0
  public static Geometry obtenerGeometriaParcela(String dxf, WorkbenchContext context) {

    Geometry geometryParcela = null;

    GeopistaLoadDxfQueryChooser dxfLoad =
        new GeopistaLoadDxfQueryChooser(Dxf.class, "GEOPISTA dxf", extensions(Dxf.class), context);

    InputStream fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf);

    try {
      Assert.isTrue(!dxfLoad.getDataSourceQueries(fileDXF).isEmpty());
    } catch (AssertionFailedException e) {
      throw new AssertionFailedException(I18N.get("FileEmpty"));
    }

    fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf);

    boolean exceptionsEncountered = false;
    for (Iterator i = dxfLoad.getDataSourceQueries(fileDXF).iterator(); i.hasNext(); ) {
      DataSourceQuery dataSourceQuery = (DataSourceQuery) i.next();

      ArrayList exceptions = new ArrayList();
      Assert.isTrue(dataSourceQuery.getDataSource().isReadable());

      Connection connection = dataSourceQuery.getDataSource().getConnection();
      try {
        FeatureCollection dataset =
            dataSourceQuery
                .getDataSource()
                .installCoordinateSystem(
                    connection.executeQuery(dataSourceQuery.getQuery(), exceptions, null), null);
        if (dataset != null) {

          String layerName = dataSourceQuery.toString();
          Geometry geometriaInicial = null;
          GeopistaFeature featureInicial = null;

          if (layerName.startsWith("PG-LP")) {
            // Obtener el borde con las features de la capa
            ArrayList lstFeatures = new ArrayList();
            for (Iterator features = dataset.getFeatures().iterator(); features.hasNext(); ) {
              GeopistaFeature feature = (GeopistaFeature) features.next();
              lstFeatures.add(feature);
            }
            ArrayList coordenadas = new ArrayList();

            if (lstFeatures != null && lstFeatures.size() > 0) {

              featureInicial = (GeopistaFeature) lstFeatures.iterator().next();
              lstFeatures.remove(featureInicial);
              geometriaInicial = featureInicial.getGeometry();
              for (int indice = 0; indice < geometriaInicial.getCoordinates().length; indice++)
                coordenadas.add(geometriaInicial.getCoordinates()[indice]);

              if (geometriaInicial instanceof LineString) {

                Point puntoFinal = ((LineString) geometriaInicial).getEndPoint();
                GeopistaFeature feature = null;
                Geometry geometria = null;
                int indice;

                while (lstFeatures.size() > 0) {
                  boolean encontrado = false;
                  Iterator features = lstFeatures.iterator();
                  while (features.hasNext() && !encontrado) {

                    feature = (GeopistaFeature) features.next();
                    geometria = feature.getGeometry();
                    if (geometria instanceof LineString) {

                      if (puntoFinal.distance(((LineString) geometria).getStartPoint()) == 0) {

                        for (indice = 1; indice < geometria.getCoordinates().length; indice++)
                          coordenadas.add(geometria.getCoordinates()[indice]);
                        puntoFinal = ((LineString) geometria).getEndPoint();
                        encontrado = true;

                      } else if (puntoFinal.distance(((LineString) geometria).getEndPoint()) == 0) {
                        for (indice = geometria.getCoordinates().length - 2; indice >= 0; indice--)
                          coordenadas.add(geometria.getCoordinates()[indice]);

                        puntoFinal = ((LineString) geometria).getStartPoint();
                        encontrado = true;
                      }
                    }
                  }
                  if (encontrado) {
                    lstFeatures.remove(feature);
                  }
                }
                Coordinate[] coordenadasParcela = new Coordinate[coordenadas.size()];
                indice = 0;
                for (Iterator coordenada = coordenadas.iterator(); coordenada.hasNext(); ) {
                  coordenadasParcela[indice] = (Coordinate) coordenada.next();
                  indice++;
                }

                if (coordenadasParcela[0].equals3D(
                    coordenadasParcela[coordenadasParcela.length - 1])) {
                  LinearRing lineaParcela =
                      geometriaInicial.getFactory().createLinearRing(coordenadasParcela);
                  Polygon poligonoParcela = null;
                  poligonoParcela = geometriaInicial.getFactory().createPolygon(lineaParcela, null);
                  geometryParcela = poligonoParcela;
                }
              }
            }
          }
        }
      } finally {
        connection.close();
      }
      if (!exceptions.isEmpty()) {
        if (!exceptionsEncountered) {
          context.getIWorkbench().getFrame().getOutputFrame().createNewDocument();
          exceptionsEncountered = true;
        }
        reportExceptions(exceptions, dataSourceQuery, context);
      }
    }
    if (exceptionsEncountered) {
      context
          .getIWorkbench()
          .getGuiComponent()
          .warnUser("Problems were encountered. See Output Window for details.");
    }

    return geometryParcela;
  }