private String[] getDriverNames() { Class[] classes = new Class[] {IVectorialDatabaseDriver.class}; ArrayList ret = new ArrayList(); String[] driverNames = LayerFactory.getDM().getDriverNames(); for (int i = 0; i < driverNames.length; i++) { for (int j = 0; j < classes.length; j++) { if (LayerFactory.getDM().isA(driverNames[i], classes[j])) { ret.add(driverNames[i]); } } } return (String[]) ret.toArray(new String[0]); }
private static void doSetup() throws Exception { String fwAndamiDriverPath = TestProperties.driversPath; File baseDriversPath = new File(fwAndamiDriverPath); if (!baseDriversPath.exists()) { throw new Exception("Can't find drivers path: " + fwAndamiDriverPath); } LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath()); if (LayerFactory.getDM().getDriverNames().length < 1) { throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath); } }
public void execute(String actionCommand) { if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) { IWindow w = PluginServices.getMDIManager().getActiveWindow(); if (w instanceof View) { try { String _file = createResourceUrl("images/new_geodb_table.png").getFile(); ImageIcon iicon = new ImageIcon(_file); DriverManager writerManager = LayerFactory.getDM(); WizardAndami wizard = new WizardAndami(iicon); RepeatedChooseGeometryTypePanel panelChoose = new RepeatedChooseGeometryTypePanel(wizard.getWizardComponents()); RepeatedFieldDefinitionPanel panelFields = new RepeatedFieldDefinitionPanel(wizard.getWizardComponents()); NewVectorDBConnectionPanel connPanel = new NewVectorDBConnectionPanel( wizard.getWizardComponents(), OracleSpatialDriver.NAME, OracleSpatialDriver.MAX_ID_LENGTH); wizard.getWizardComponents().addWizardPanel(panelChoose); wizard.getWizardComponents().addWizardPanel(panelFields); wizard.getWizardComponents().addWizardPanel(connPanel); Driver driver = new OracleSpatialDriver(); panelFields.setWriter(((IWriteable) driver).getWriter()); panelChoose.setDriver(driver); View theView = (View) w; MapContext mc = theView.getMapControl().getMapContext(); NewOracleSpatialTableFinishAction action = new NewOracleSpatialTableFinishAction( wizard.getWizardComponents(), wizard, connPanel, mc); wizard.getWizardComponents().setFinishAction(action); wizard.getWizardComponents().getFinishButton().setEnabled(false); wizard.getWindowInfo().setWidth(640); wizard.getWindowInfo().setHeight(350); wizard.getWindowInfo().setTitle(PluginServices.getText(this, "new_layer")); PluginServices.getMDIManager().addWindow(wizard); } catch (Exception ex) { logger.error("While showing new oracle spatial table wizard: " + ex.getMessage()); } } } }
public void actionPerformed(ActionEvent arg0) { Object src = arg0.getSource(); if (src == connectedCheckBox) { if (connectedCheckBox.isSelected()) { passwordField.setEnabled(true); passwordField.setBackground(Color.WHITE); } else { passwordField.setText(""); passwordField.setEnabled(false); passwordField.setBackground(Color.LIGHT_GRAY); } } if (src == okButton) { okPressed = true; PluginServices.getMDIManager().closeWindow(this); return; } if (src == cancelButton) { okPressed = false; PluginServices.getMDIManager().closeWindow(this); return; } if (src == driverComboBox) { String driverName = driverComboBox.getSelectedItem().toString(); IVectorialDatabaseDriver driver; try { driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName); portTextField.setText("" + driver.getDefaultPort()); } catch (DriverLoadException e1) { portTextField.setText(""); } return; } }
/** * Creating dbf format file with the statistics * * @param valores - Pairs String name (key) + Double value * @param endFile - File to write the information */ private void exportToDBFFile(List<MyObjectStatistics> valores, File endFile) { try { FileDriver driver = null; try { driver = (FileDriver) LayerFactory.getDM().getDriver("gdbms dbf driver"); } catch (DriverLoadException e1) { logger.error("Error Creando el driver dbf"); } try { if (!endFile.exists()) { try { driver.createSource( endFile.getAbsolutePath(), new String[] {"0"}, new int[] {Types.DOUBLE}); } catch (ReadDriverException e) { logger.error("Error en createSource"); } endFile.createNewFile(); } try { driver.open(endFile); } catch (OpenDriverException e) { logger.error("Error abriendo el fichero de destino"); } } catch (IOException e) { try { throw new Exception("Error creando el fichero de destino", e); } catch (Exception e1) { logger.error("Error creando el fichero de destino"); } } IWriter writer = ((IWriteable) driver).getWriter(); ITableDefinition orgDef = new TableDefinition(); try { // Preparing the total rows in the new dbf file, in this case // two rows : Name Value FieldDescription[] fields = new FieldDescription[2]; fields[0] = new FieldDescription(); fields[0].setFieldType(Types.VARCHAR); fields[0].setFieldName(PluginServices.getText(this, "Nombre")); fields[0].setFieldLength(50); fields[1] = new FieldDescription(); fields[1].setFieldType(Types.DOUBLE); fields[1].setFieldName(PluginServices.getText(this, "Valor")); fields[1].setFieldLength(50); fields[1].setFieldDecimalCount(25); fields[1].setFieldLength(100); orgDef.setFieldsDesc(fields); writer.initialize(orgDef); } catch (InitializeWriterException e) { logger.error("Error en la inicialización del writer"); } try { writer.preProcess(); } catch (StartWriterVisitorException e) { logger.error("Error en el preProcess del writer"); } try { int index = 0; Value[] value = new Value[2]; IFeature feat = null; Iterator<MyObjectStatistics> iterador = valores.listIterator(); while (iterador.hasNext()) { MyObjectStatistics data = (MyObjectStatistics) iterador.next(); value[0] = ValueFactory.createValue(data.getKey()); value[1] = ValueFactory.createValue(data.getValue()); feat = new DefaultFeature(null, value, "" + index++); write(writer, feat, index); } } catch (Exception e) { logger.error("Error en el write"); } try { writer.postProcess(); // Operation finished JOptionPane.showMessageDialog( null, PluginServices.getText(this, "fichero_creado_en") + " " + endFile.getAbsolutePath(), PluginServices.getText(this, "fichero_creado_en_formato") + " dbf", JOptionPane.INFORMATION_MESSAGE); // Informing the user } catch (StopWriterVisitorException e) { logger.error("Error en el postProcess del writer"); } } catch (Exception e) { // Informing the user logger.error("Error exportando a formato dbf"); JOptionPane.showMessageDialog( null, PluginServices.getText(this, "Error_exportando_las_estadisticas") + " " + endFile.getAbsolutePath(), PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE); } }