List of usage examples for java.util Vector addAll
public boolean addAll(Collection<? extends E> c)
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Export to XLS .// w w w. ja v a 2s.c o m */ protected void doExcelCsvExport() { int[] selection = spreadSheet.getSelectedRowModelIndexes(); if (selection.length == 0) { // if none are selected, map all of them int rowCnt = spreadSheet.getRowCount(); selection = new int[rowCnt]; for (int i = 0; i < rowCnt; ++i) { selection[i] = spreadSheet.convertRowIndexToModel(i); } } // put all the selected rows in a List List<WorkbenchRow> selectedRows = new Vector<WorkbenchRow>(); List<WorkbenchRow> rows = workbench.getWorkbenchRowsAsList(); for (int i = 0; i < selection.length; ++i) { int index = selection[i]; WorkbenchRow row = rows.get(index); selectedRows.add(row); } CommandAction command = new CommandAction(PluginsTask.PLUGINS, PluginsTask.EXPORT_LIST); command.setData(selectedRows); command.setProperty("tool", ExportToFile.class); Properties props = new Properties(); if (!WorkbenchTask.getExportInfo(props, workbench.getName())) { return; } ConfigureExternalDataIFace config = ExportFileConfigurationFactory.getConfiguration(props); // Could get config to interactively get props or to look them up from prefs or ??? // for now hard coding stuff... // add headers. all the time for now. config.setFirstRowHasHeaders(true); Vector<WorkbenchTemplateMappingItem> colHeads = new Vector<WorkbenchTemplateMappingItem>(); colHeads.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems()); Collections.sort(colHeads); String[] heads = new String[colHeads.size()]; for (int h = 0; h < colHeads.size(); h++) { heads[h] = colHeads.get(h).getCaption(); } config.setHeaders(heads); command.addProperties(config.getProperties()); UsageTracker.incrUsageCount("WB.ExportXLSRowsTool"); CommandDispatcher.dispatch(command); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Adjust all the column width for the data in the column, this may be handles with JDK 1.6 (6.) * @param tableArg the table that should have it's columns adjusted *//*from w ww.j a v a 2s.c o m*/ private void initColumnSizes(final JTable tableArg, final JButton theSaveBtn) throws Exception { TableModel tblModel = tableArg.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; Element uploadDefs = null; if (WorkbenchTask.isCustomizedSchema()) { uploadDefs = XMLHelper.readFileToDOM4J( new File(UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml")); } else { uploadDefs = XMLHelper.readDOMFromConfigDir("specify_workbench_upload_def.xml"); } //UIRegistry.getInstance().hookUpUndoableEditListener(cellEditor); Vector<WorkbenchTemplateMappingItem> wbtmis = new Vector<WorkbenchTemplateMappingItem>(); wbtmis.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems()); Collections.sort(wbtmis); DBTableIdMgr databaseSchema = WorkbenchTask.getDatabaseSchema(); columnMaxWidths = new Integer[tableArg.getColumnCount()]; for (int i = 0; i < wbtmis.size() /*tableArg.getColumnCount()*/; i++) { TableCellRenderer headerRenderer = tableArg.getColumnModel().getColumn(i).getHeaderRenderer(); WorkbenchTemplateMappingItem wbtmi = wbtmis.elementAt(i); // Now go retrieve the data length int fieldWidth = WorkbenchDataItem.getMaxWBCellLength(); DBTableInfo ti = databaseSchema.getInfoById(wbtmi.getSrcTableId()); if (ti != null) { DBFieldInfo fi = ti.getFieldByName(wbtmi.getFieldName()); if (fi != null) { wbtmi.setFieldInfo(fi); //System.out.println(fi.getName()+" "+fi.getLength()+" "+fi.getType()); if (RecordTypeCodeBuilder.getTypeCode(fi) == null && fi.getLength() > 0) { fieldWidth = Math.min(fi.getLength(), WorkbenchDataItem.getMaxWBCellLength()); } } else { log.error("Can't find field with name [" + wbtmi.getFieldName() + "]"); } } else { log.error("Can't find table [" + wbtmi.getSrcTableId() + "]"); } columnMaxWidths[i] = new Integer(fieldWidth); GridCellEditor cellEditor = getCellEditor(wbtmi, fieldWidth, theSaveBtn, uploadDefs); column = tableArg.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = tableArg.getDefaultRenderer(tblModel.getColumnClass(i)).getTableCellRendererComponent(tableArg, tblModel.getValueAt(0, i), false, false, 0, i); cellWidth = comp.getPreferredSize().width; //comp.setBackground(Color.WHITE); int maxWidth = headerWidth + 10; TableModel m = tableArg.getModel(); FontMetrics fm = comp.getFontMetrics(comp.getFont()); for (int row = 0; row < tableArg.getModel().getRowCount(); row++) { String text = m.getValueAt(row, i).toString(); maxWidth = Math.max(maxWidth, fm.stringWidth(text) + 10); //log.debug(i+" "+maxWidth); } //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead. //log.debug(Math.max(maxWidth, cellWidth)); //log.debug(Math.min(Math.max(maxWidth, cellWidth), 400)); column.setPreferredWidth(Math.min(Math.max(maxWidth, cellWidth), 400)); column.setCellEditor(cellEditor); } //tableArg.setCellEditor(cellEditor); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java
/** * @return for an exported dataset, fields that are not the same * as the corresponding fields in the database for the given row, because * they have been edited in the workbench or by other means. * /* w w w .ja va 2 s . c om*/ * NOTE: Assumes loadRecord() has been called for row for the 'root' table * of the dataset. */ protected List<UploadField> getChangedFields(int row) throws UploaderException, InvocationTargetException, IllegalAccessException, NoSuchMethodException { Vector<UploadField> result = new Vector<UploadField>(); if (uploadFields.size() > 1) { //ouch } else { result.addAll(getChangedFields(row, 0)); } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Carry forward configuration.//from w ww . j a v a 2s .c o m */ public void configCarryFoward() { Vector<WorkbenchTemplateMappingItem> items = new Vector<WorkbenchTemplateMappingItem>(); Vector<WorkbenchTemplateMappingItem> selectedObjects = new Vector<WorkbenchTemplateMappingItem>(); items.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems()); for (WorkbenchTemplateMappingItem item : items) { if (item.getCarryForward()) { selectedObjects.add(item); } } // turn off alwaysOnTop for Swing repaint reasons (prevents a lock up) imageFrame.setAlwaysOnTop(false); Collections.sort(items); ToggleButtonChooserDlg<WorkbenchTemplateMappingItem> dlg = new ToggleButtonChooserDlg<WorkbenchTemplateMappingItem>( (Frame) UIRegistry.get(UIRegistry.FRAME), "WB_CARRYFORWARD", "WB_CHOOSE_CARRYFORWARD", items, CustomDialog.OKCANCELHELP, ToggleButtonChooserPanel.Type.Checkbox); dlg.setHelpContext( currentPanelType == PanelType.Spreadsheet ? "WorkbenchGridEditingCF" : "WorkbenchFormEditingCF"); dlg.setAddSelectAll(true); dlg.setSelectedObjects(selectedObjects); dlg.setModal(true); dlg.setAlwaysOnTop(true); dlg.setUseScrollPane(true); dlg.setVisible(true); if (!dlg.isCancelled()) { for (WorkbenchTemplateMappingItem item : items) { item.setCarryForward(false); } for (WorkbenchTemplateMappingItem item : dlg.getSelectedObjects()) { item.setCarryForward(true); } setChanged(true); } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java
/** * @return all tables that precede this table in the Upload graph *///from ww w . j av a 2s . c o m public Vector<ParentTableEntry> getAncestors() { Vector<ParentTableEntry> result = new Vector<ParentTableEntry>(); for (Vector<ParentTableEntry> ptes : parentTables) { for (ParentTableEntry pte : ptes) { result.add(pte); result.addAll(pte.getImportTable().getAncestors()); } } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Shows a dialog that enales the user to convert the lat/lon formats. */// ww w.j a v a 2 s.c o m protected void showGeoRefConvertDialog() { if (geoRefConvertDlg != null) { geoRefConvertDlg.toFront(); return; } UsageTracker.incrUsageCount("WB.ShowGeoRefConverter"); JStatusBar statusBar = UIRegistry.getStatusBar(); if (!workbench.containsGeoRefData()) { statusBar.setErrorMessage(getResourceString("NoGeoRefColumns")); return; } List<String> outputFormats = new Vector<String>(); String dddddd = getResourceString("DDDDDD"); String ddmmmm = getResourceString("DDMMMM"); String ddmmss = getResourceString("DDMMSS"); String ddddddnsew = getResourceString("DDDDDDNSEW"); String ddmmmmnsew = getResourceString("DDMMMMNSEW"); String ddmmssnsew = getResourceString("DDMMSSNSEW"); outputFormats.add(dddddd); outputFormats.add(ddmmmm); outputFormats.add(ddmmss); outputFormats.add(ddddddnsew); outputFormats.add(ddmmmmnsew); outputFormats.add(ddmmssnsew); final int locTabId = DBTableIdMgr.getInstance().getIdByClassName(Locality.class.getName()); final int latColIndex = workbench.getColumnIndex(locTabId, "latitude1"); final int lonColIndex = workbench.getColumnIndex(locTabId, "longitude1"); final int lat2ColIndex = workbench.getColumnIndex(locTabId, "latitude2"); final int lon2ColIndex = workbench.getColumnIndex(locTabId, "longitude2"); JFrame mainFrame = (JFrame) UIRegistry.getTopWindow(); String title = UIRegistry.getResourceString("GeoRefConv"); String description = UIRegistry.getResourceString("GeoRefConvDesc"); final ToggleButtonChooserPanel<String> toggle = new ToggleButtonChooserPanel<String>(outputFormats, description, Type.RadioButton); final JCheckBox symbolCkBx = UIHelper.createCheckBox(UIRegistry.getResourceString("GEOREF_USE_SYMBOLS")); JPanel pane = new JPanel(new BorderLayout()); pane.add(toggle, BorderLayout.CENTER); pane.add(symbolCkBx, BorderLayout.SOUTH); geoRefConvertDlg = new CustomDialog(mainFrame, title, false, CustomDialog.OKCANCEL, pane) { @Override public void setVisible(boolean visible) { super.setVisible(visible); Dimension prefSize = this.getPreferredSize(); prefSize.width += 60; this.setSize(prefSize); } @Override protected void cancelButtonPressed() { geoRefConvertDlg = null; super.cancelButtonPressed(); } @Override protected void okButtonPressed() { checkCurrentEditState(); // figure out which rows the user is working with int[] selection = spreadSheet.getSelectedRowModelIndexes(); if (selection.length == 0) { // if none are selected, map all of them int rowCnt = spreadSheet.getRowCount(); selection = new int[rowCnt]; for (int i = 0; i < rowCnt; ++i) { selection[i] = spreadSheet.convertRowIndexToModel(i); } } // since Arrays.copyOf() isn't in Java SE 5... int[] selRows = new int[selection.length]; for (int i = 0; i < selection.length; ++i) { selRows[i] = selection[i]; } // don't call super.okButtonPressed() b/c it will close the window isCancelled = false; btnPressed = OK_BTN; LatLonConverter.DEGREES_FORMAT degFmt = symbolCkBx.isSelected() ? LatLonConverter.DEGREES_FORMAT.Symbol : LatLonConverter.DEGREES_FORMAT.None; Vector<CellPosition> unconverted = new Vector<CellPosition>(); switch (toggle.getSelectedIndex()) { case 0: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 1: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 2: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 3: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 4: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 5: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } } if (unconverted.size() != 0) { UIRegistry.displayLocalizedStatusBarError("WB_UNCONVERTED_GEOREFS", unconverted.size()); final JList<?> unconvertedcells = UIHelper.createList(unconverted); unconvertedcells.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent arg0) { CellPosition rowCol = (CellPosition) unconvertedcells.getSelectedValue(); spreadSheet.scrollCellToVisible(rowCol.getFirst(), rowCol.getSecond()); } }); JLabel lbl = UIHelper.createLabel(UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_MSG")); JPanel innerPane = new JPanel(new BorderLayout()); innerPane.add(lbl, BorderLayout.NORTH); innerPane.add(unconvertedcells, BorderLayout.CENTER); CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(), UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_TITLE"), false, CustomDialog.OKHELP, innerPane); cd.setHelpContext("UnconvertableGeoCoords"); UIHelper.centerAndShow(cd); } } }; geoRefConvertDlg.setModal(false); toggle.setSelectedIndex(0); toggle.setOkBtn(geoRefConvertDlg.getOkBtn()); toggle.createUI(); geoRefConvertDlg.addWindowListener(new WindowListener() { /* (non-Javadoc) * @see java.awt.event.WindowStateListener#windowStateChanged(java.awt.event.WindowEvent) */ @Override public void windowClosed(WindowEvent e) { geoRefConvertDlg = null; } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent) */ @Override public void windowActivated(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) */ @Override public void windowClosing(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent) */ @Override public void windowDeactivated(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent) */ @Override public void windowDeiconified(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent) */ @Override public void windowIconified(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent) */ @Override public void windowOpened(WindowEvent arg0) { // TODO Auto-generated method stub } }); geoRefConvertDlg.setOkLabel(getResourceString("APPLY")); geoRefConvertDlg.setCancelLabel(getResourceString("CLOSE")); geoRefConvertDlg.setVisible(true); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java
/** * Validates contents of all cells in dataset. *//*w w w .java 2 s .c om*/ public boolean validateData(boolean doInBackground) { dataValidated = false; setOpKiller(null); final Vector<UploadTableInvalidValue> issues = new Vector<UploadTableInvalidValue>(); final UploaderTask validateTask = new UploaderTask(true, "WB_UPLOAD_CANCEL_MSG") { @Override public Object doInBackground() { start(); try { int progress = 0; initProgressBar(0, uploadTables.size(), true, getResourceString("WB_UPLOAD_VALIDATING") + " " + getResourceString("ERD_TABLE"), false); for (UploadTable tbl : uploadTables) { tbl.clearBlankness(); } for (UploadTable tbl : uploadTables) { setCurrentOpProgress(++progress); issues.addAll(validateLengths(tbl, -1, -1)); issues.addAll(tbl.validateValues(uploadData)); } Collections.sort(issues); dataValidated = issues.size() == 0; return dataValidated; } catch (Exception ex) { setOpKiller(ex); return false; } } @Override public void done() { super.done(); validationIssues = issues; statusBar.setText(""); if (cancelled) { setCurrentOp(Uploader.INITIAL_STATE); } else if (dataValidated && resolver.isResolved() && mainPanel != null) { mainPanel.addMsg(new BaseUploadMessage(getResourceString("WB_DATASET_VALIDATED"))); setCurrentOp(Uploader.READY_TO_UPLOAD); } else if (mainPanel != null) { mainPanel.addMsg(new BaseUploadMessage(getResourceString("WB_INVALID_DATASET"))); setCurrentOp(Uploader.USER_INPUT); } } // /* (non-Javadoc) // * @see edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.UploaderTask#cancelTask() // */ // @Override // public synchronized void cancelTask() // { // super.cancelTask(); // interrupt(); // } }; SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { UIRegistry.getStatusBar().setText(getResourceString(Uploader.VALIDATING_DATA)); } }); boolean result = true; validateTask.execute(); if (!doInBackground) { try { result = (Boolean) validateTask.get(); } catch (ExecutionException ex) { //hopefully it will be clear to caller that something went wrong? } catch (InterruptedException ex) { //hopefully it will be clear to caller that something went wrong? } //validateTask.finished(); //validateTask. } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java
/** * @return true if the dataset can be uploaded. * //from w w w . java2 s .c o m * Checks that the import mapping and graph are OK. Checks that all required data (TreeDefs, * TreeDefItems, DeterminationStatuses, etc) is present in the database. * * Saves messages for each problem. */ public Vector<UploadMessage> verifyUploadability() throws UploaderException, ClassNotFoundException { Vector<UploadMessage> errors = new Vector<UploadMessage>(); try { Vector<Vector<Table>> missingTbls = new Vector<Vector<Table>>(); //check that parents exist for one-to-one children (which are required to be defined as many-to-one parents //in hibernate) for (UploadTable t : uploadTables) { if (t.isOneToOneChild() && !t.getHasChildren() && !(t.getTblClass().equals(LocalityDetail.class) || t.getTblClass().equals(GeoCoordDetail.class))) { Vector<Vertex<Table>> vs = db.getGraph() .getAdjacentVertices(new Vertex<Table>(t.getTable().getName(), t.getTable())); Vector<Table> tbls = new Vector<Table>(); for (Vertex<Table> vertex : vs) { tbls.add(vertex.getData()); } missingTbls.add(tbls); } } if (!uploadGraph.isConnected()) { missingTbls.addAll(getMissingTbls()); } if (missingTbls.size() > 0) { Vector<Pair<String, Vector<Table>>> missingTblHints = new Vector<Pair<String, Vector<Table>>>(); int h = 1; for (Vector<Table> tbls : missingTbls) { String msg = ""; if (tbls != null && tbls.size() > 0) { msg += " "; for (int t = 0; t < tbls.size(); t++) { if (t > 0) { msg += ", "; } msg += tbls.get(t).getTableInfo().getTitle(); } } if (!msg.equals("")) { missingTblHints.add(new Pair<String, Vector<Table>>( String.format(getResourceString("WB_UPLOAD_MISSING_TBL_HINT"), h++, msg), tbls)); } } if (missingTblHints.size() > 0) { errors.add(new BaseUploadMessage(getResourceString("WB_UPLOAD_MISSING_TBL_HINTS"))); for (Pair<String, Vector<Table>> hint : missingTblHints) { errors.add(new InvalidStructure(" " + hint.getFirst(), hint.getSecond())); } } else { errors.add(new BaseUploadMessage(getResourceString("WB_UPLOAD_MISSING_TBL_NO_HINTS"))); } } } catch (DirectedGraphException ex) { throw new UploaderException(ex, UploaderException.ABORT_IMPORT); } errors.addAll(validateConsistency()); if (!verifyAttachments()) { String msg = String.format(UIRegistry.getResourceString("WB_UPLOAD_NO_ATTACHABLES"), getAttachableStr()); errors.add(new BaseUploadMessage(msg)); } //if tables are missing return now, because spurious errors may be generated. if (errors.size() != 0) { return errors; } // now find out what data is not available in the dataset and not available in the database // Considering such issues 'structural' for now. missingRequiredClasses.clear(); missingRequiredFields.clear(); Iterator<RelatedClassSetter> rces; Iterator<DefaultFieldEntry> dfes; for (UploadTable t : uploadTables) { try { rces = t.getRelatedClassDefaults(); } catch (ClassNotFoundException ex) { log.error(ex); return null; } while (rces.hasNext()) { missingRequiredClasses.add(rces.next()); } try { dfes = t.getMissingRequiredFlds(); } catch (NoSuchMethodException ex) { log.error(ex); return null; } while (dfes.hasNext()) { missingRequiredFields.add(dfes.next()); } } resolver = new MissingDataResolver(missingRequiredClasses, missingRequiredFields); for (RelatedClassSetter rcs : missingRequiredClasses) { if (!rcs.isDefined()) { // Assume it is undefined because no related data exists in the database. // Also assuming (currently erroneously) that definition problems related to // choosing // from multiple existing related data have been resolved through user interaction. String tblName = DBTableIdMgr.getInstance() .getByShortClassName(rcs.getRelatedClass().getSimpleName()).getTitle(); // a very vague message... String msg = getResourceString("WB_UPLOAD_MISSING_DBDATA") + ": " + tblName; errors.add(new InvalidStructure(msg, this)); } } Vector<DefaultFieldEntry> undefinedDfes = new Vector<DefaultFieldEntry>(); for (DefaultFieldEntry dfe : missingRequiredFields) { if (!dfe.isDefined()) { undefinedDfes.add(dfe); } } //now remove possibly confusing or redundant dfes. Collections.sort(undefinedDfes, new Comparator<DefaultFieldEntry>() { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(DefaultFieldEntry o1, DefaultFieldEntry o2) { int result = o1.getUploadTbl().getTable().getName() .compareTo(o2.getUploadTbl().getTable().getName()); if (result != 0) { return result; } boolean o1IsUserFld = o1.getUploadFld() == null || o1.getUploadFld().getIndex() != -1; boolean o2IsUserFld = o2.getUploadFld() == null || o2.getUploadFld().getIndex() != -1; if (o1IsUserFld == o2IsUserFld) { return (o1.getFldName().compareTo(o2.getFldName())); } if (o1IsUserFld) { return -1; } return 1; } }); UploadTable currentTbl = null; Vector<DefaultFieldEntry> dfes4Tbl = new Vector<DefaultFieldEntry>(); Vector<DefaultFieldEntry> dfes2Remove = new Vector<DefaultFieldEntry>(); for (DefaultFieldEntry dfe : undefinedDfes) { if (dfe.getUploadTbl() != currentTbl) { if (dfes4Tbl.size() > 1) { boolean gotAUserFld = false; for (DefaultFieldEntry tblDfe : dfes4Tbl) { boolean isAUserFld = tblDfe.getUploadFld() == null || tblDfe.getUploadFld().getIndex() != -1; gotAUserFld = gotAUserFld || isAUserFld; if (!isAUserFld && gotAUserFld) { //remove weird fields if there are other non-weird fields from the table dfes2Remove.add(tblDfe); } } } dfes4Tbl.clear(); currentTbl = dfe.getUploadTbl(); } dfes4Tbl.add(dfe); } if (dfes4Tbl.size() > 1) { boolean gotAUserFld = false; for (DefaultFieldEntry tblDfe : dfes4Tbl) { boolean isAUserFld = tblDfe.getUploadFld() == null || tblDfe.getUploadFld().getIndex() != -1; gotAUserFld = gotAUserFld || isAUserFld; if (!isAUserFld && gotAUserFld) { //remove weird fields if there are other non-weird(or weird) fields from the table dfes2Remove.add(tblDfe); } } } for (DefaultFieldEntry dfe : dfes2Remove) { undefinedDfes.remove(dfe); } for (DefaultFieldEntry dfe : undefinedDfes) { // see note above for missignRequiredClasses iteration // another very vague message... String msg = getResourceString("WB_UPLOAD_MISSING_DBDATA") + ": " + dfe.getUploadTbl().getTable().getTableInfo().getTitle() + "." + dfe.getFldName(); // i18n (dfe.getFldName() is not using title nor wb // column header) errors.add(new InvalidStructure(msg, this)); } for (UploadTable t : uploadTables) { errors.addAll(t.verifyUploadability()); } return errors; }
From source file:edu.ku.brc.af.ui.forms.FormViewObj.java
/** * Creates a special drop "switcher UI" component for switching between the Viewables in the MultiView. * @param mvParentArg the MultiView Parent * @param viewArg the View/*from w ww .j a v a2 s. c o m*/ * @param altViewArg the AltViewIFace * @param altViewsListArg the Vector of AltViewIFace that will contains the ones in the Drop Down * @return the special combobox * @param restrictableUI * @param cellName the name of the cell when it is a subview * @param dataClass the class of the data that is put into the form * @return */ public static MenuSwitcherPanel createMenuSwitcherPanel(final MultiView mvParentArg, final ViewIFace viewArg, final AltViewIFace altViewArg, final Vector<AltViewIFace> altViewsListArg, final RestrictableUIIFace restrictableUI, final String cellName, final Class<?> dataClass) { if (AppContextMgr.isSecurityOn()) { PermissionSettings perm = MultiView.getPremissionFromView(viewArg, MultiView.getClassNameFromParentMV(dataClass, mvParentArg, cellName)); //PermissionSettings.dumpPermissions(mvParentArg.getViewName(), perm.getOptions()); if (perm.hasNoPerm() && restrictableUI != null) { restrictableUI.setRestricted(true); } AltViewIFace.CreationMode mode = altViewArg.getMode(); for (AltViewIFace av : viewArg.getAltViews()) { boolean isSecurityModeOK = perm.getOptions() > 0 && ((perm.isViewOnly() && (mode == AltViewIFace.CreationMode.VIEW)) || !perm.isViewOnly()); //PermissionSettings.dumpPermissions(viewArg.getClassName()+" "+isSecurityModeOK+" "+av.getTitle()+" "+mode, perm.getOptions()); if (isSecurityModeOK && (av.getMode() == mode || (mvParentArg.isTopLevel() && mvParentArg.isOKToAddAllAltViews()))) { altViewsListArg.add(av); } } } else { // Add all the View if we are at the top level // If not, then we are a subform and we should only add the view that belong to our same creation mode. if (mvParentArg.isTopLevel() && mvParentArg.isOKToAddAllAltViews()) { altViewsListArg.addAll(viewArg.getAltViews()); } else { AltViewIFace.CreationMode mode = altViewArg.getMode(); for (AltViewIFace av : viewArg.getAltViews()) { if (av.getMode() == mode) { altViewsListArg.add(av); } } } } return altViewsListArg.size() > 1 ? new MenuSwitcherPanel(mvParentArg, altViewArg, altViewsListArg) : null; }
From source file:lu.fisch.unimozer.Diagram.java
public Vector<MyClass> getChildClasses(String of) { Vector<MyClass> ret = new Vector<MyClass>(); /*Set<String> set = classes.keySet(); Iterator<String> itr = set.iterator(); while (itr.hasNext())/* www . j a v a 2 s. c o m*/ { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass mc = classes.get(str); if (mc.getExtendsClass() != null) { if (mc.getExtendsClass().equals(of)) { ret.add(mc); ret.addAll(getChildClasses(str)); } } Vector<MyClass> uses = mc.getUsesMyClass(); for (MyClass mac : uses) { if (mac.getShortName().equals(of)) { ret.add(mc); ret.addAll(getChildClasses(str)); } } } return ret; }