List of usage examples for javax.swing JList getSelectedIndex
public int getSelectedIndex()
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * /*from w ww .j a v a2s . c o m*/ */ protected void exportResource() { int index = levelCBX.getSelectedIndex(); if (index > -1) { String exportedName = null; String data = null; String fileName = null; AppResourceIFace appRes = null; if (tabbedPane.getSelectedComponent() == viewsPanel) { if (viewSetsList.getSelectedIndex() > -1) { SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue(); exportedName = vso.getName(); fileName = FilenameUtils.getName(vso.getFileName()); data = vso.getDataAsString(true); } } else { JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList; if (theList.getSelectedIndex() > 0) { appRes = (AppResourceIFace) theList.getSelectedValue(); exportedName = appRes.getName(); fileName = FilenameUtils.getName(exportedName); data = appRes.getDataAsString(); } } if (StringUtils.isNotEmpty(data)) { final String EXP_DIR_PREF = "RES_LAST_EXPORT_DIR"; String initalExportDir = AppPreferences.getLocalPrefs().get(EXP_DIR_PREF, getUserHomeDir()); FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_ExportResource"), FileDialog.SAVE); File expDir = new File(initalExportDir); if (StringUtils.isNotEmpty(initalExportDir) && expDir.exists()) { fileDlg.setDirectory(initalExportDir); } fileDlg.setFile(fileName); UIHelper.centerAndShow(fileDlg); String dirStr = fileDlg.getDirectory(); fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) { AppPreferences.getLocalPrefs().put(EXP_DIR_PREF, dirStr); File expFile = new File(dirStr + File.separator + fileName); try { if (isReportResource((SpAppResource) appRes) && isSpReportResource((SpAppResource) appRes)) { writeSpReportResToZipFile(expFile, data, appRes); } else { FileUtils.writeStringToFile(expFile, data); } } catch (FileNotFoundException ex) { showLocalizedMsg("RIE_NOFILEPERM"); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, ex); } } } if (exportedName != null) { getStatusBar().setText(getLocalizedMessage("RIE_RES_EXPORTED", exportedName)); } } }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * Revert a resource. Re-read it from the disk. *//*from ww w . j a v a 2 s. c om*/ protected void revertResource() { int index = levelCBX.getSelectedIndex(); if (index > -1) { String exportedName = null; String virtualDirName = SpecifyAppContextMgr.getVirtualDirName(index); if (tabbedPane.getSelectedComponent() == viewsPanel) { SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue(); if (vso != null) { exportedName = vso.getName(); index = viewSetsList.getSelectedIndex(); if (index > -1) { viewSetsModel.remove(index); contextMgr.revertViewSet(virtualDirName, vso.getName()); setHasChanged(true); } } } else { JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList; DefaultListModel theModel = theList == repList ? repModel : resModel; index = theList.getSelectedIndex(); if (index > 0) { AppResourceIFace appRes = (AppResourceIFace) theList.getSelectedValue(); AppResourceIFace revertedNewAR = contextMgr.revertResource(virtualDirName, appRes); setHasChanged(true); if (revertedNewAR != null) { theModel.insertElementAt(revertedNewAR, index); theList.setSelectedIndex(index); } else { theModel.removeElementAt(index); theList.clearSelection(); } levelSelected(); } } if (exportedName != null) { completeMsg = getLocalizedMessage("RIE_RES_REVERTED", exportedName); } enableUI(); } }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * /* www .j a va 2s. c o m*/ */ protected void createUI() { JTabbedPane tabbedPane = new JTabbedPane(); rp = new RegProcessor(); rp.processSQL(); tree = new JTree(rp.getRoot(INCL_ANON)); propsTable = new JTable(); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { fillPropsTable(); } }); tree.setCellRenderer(new MyTreeCellRenderer()); Component topComp = UIHelper.createScrollPane(tree); Component botComp = UIHelper.createScrollPane(propsTable); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp); splitPane.setDividerLocation(0.5); splitPane.setOneTouchExpandable(true); splitPane.setLastDividerLocation(300); Dimension minimumSize = new Dimension(200, 400); topComp.setMinimumSize(minimumSize); botComp.setMinimumSize(minimumSize); tabbedPane.add("Registration", splitPane); final List<Pair<String, String>> trackDescPairs = rp.getTrackKeyDescPairs(); Vector<String> trkItems = new Vector<String>(); for (Pair<String, String> p : trackDescPairs) { trkItems.add(p.second); } //Collections.sort(trkItems); final JList list = new JList(trkItems); //pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1)); list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int inx = list.getSelectedIndex(); if (inx > -1) { fillUsageItemsList(trackDescPairs.get(inx).first); } } } }); tabbedPane.add("Reg Stats", getStatsPane("Registration", rp.getRegNumHash().values(), "register")); DefaultListModel model = new DefaultListModel(); trackItemsList = new JList(model); topComp = UIHelper.createScrollPane(list); botComp = UIHelper.createScrollPane(trackItemsList); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp); splitPane.setDividerLocation(0.5); splitPane.setOneTouchExpandable(true); topComp.setMinimumSize(minimumSize); botComp.setMinimumSize(minimumSize); splitPane.setDividerLocation(0.5); trackUsageHash = rp.getTrackCatsHash(); tabbedPane.add("Usage Tracking", splitPane); tabbedPane.add("User Stats", getStatsPane("Tracking", rp.getTrackIdHash().values(), "track")); add(tabbedPane, BorderLayout.CENTER); }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * /* w ww . j a v a2s. c o m*/ */ protected void importResource() { int levelIndex = levelCBX.getSelectedIndex(); if (levelIndex > -1) { String importedName = null; final String IMP_DIR_PREF = "RES_LAST_IMPORT_DIR"; String initalImportDir = AppPreferences.getLocalPrefs().get(IMP_DIR_PREF, getUserHomeDir()); FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_IMPORT_RES"), FileDialog.LOAD); File impDir = new File(initalImportDir); if (StringUtils.isNotEmpty(initalImportDir) && impDir.exists()) { fileDlg.setDirectory(initalImportDir); } UIHelper.centerAndShow(fileDlg); String dirStr = fileDlg.getDirectory(); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) { AppPreferences.getLocalPrefs().put(IMP_DIR_PREF, dirStr); String data = null; String fullFileName = dirStr + File.separator + fileName; File importFile = new File(fullFileName); if (importFile.exists()) { String repResourceName = getSpReportResourceName(importFile); boolean isSpReportRes = repResourceName != null; boolean isJRReportRes = false; try { data = FileUtils.readFileToString(importFile); isJRReportRes = isJasperReport(data); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, ex); return; } boolean isReportRes = isJRReportRes || isSpReportRes; if (tabbedPane.getSelectedComponent() == viewsPanel) { int viewIndex = viewSetsList.getSelectedIndex(); if (viewIndex > -1) { boolean isAddItemForImport = viewSetsList.getSelectedValue() instanceof String; boolean isOK = false; SpViewSetObj vso = null; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); if (!isAddItemForImport) { vso = (SpViewSetObj) viewSetsList.getSelectedValue(); SpAppResourceDir appResDir = vso.getSpAppResourceDir(); importedName = vso.getName(); if (vso.getSpViewSetObjId() == null) { appResDir.getSpPersistedViewSets().add(vso); vso.setSpAppResourceDir(appResDir); } vso.setDataAsString(data, true); session.saveOrUpdate(appResDir); } else { SpAppResourceDir appResDir = dirs.get(levelIndex); vso = new SpViewSetObj(); vso.initialize(); vso.setLevel((short) levelIndex); vso.setName(FilenameUtils.getBaseName(importFile.getName())); appResDir.getSpPersistedViewSets().add(vso); vso.setSpAppResourceDir(appResDir); vso.setDataAsString(data); session.saveOrUpdate(appResDir); } session.saveOrUpdate(vso); for (SpAppResourceData ard : vso.getSpAppResourceDatas()) { session.saveOrUpdate(ard); } session.commit(); session.flush(); setHasChanged(true); isOK = true; completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, ex); session.rollback(); } finally { try { session.close(); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, ex); } } if (isOK) { if (isAddItemForImport) { viewSetsModel.clear(); viewSetsModel.addElement(vso); } else { viewSetsModel.remove(viewIndex); viewSetsModel.insertElementAt(vso, viewIndex); } viewSetsList.repaint(); } } } else { boolean isResourcePanel = tabbedPane.getSelectedComponent() == repPanel; JList theList = isResourcePanel ? repList : resList; int resIndex = theList.getSelectedIndex(); Object selObj = theList.getSelectedValue(); if (resIndex > -1) { if (resIndex == 0) // means we are adding a new resource { try { SpecifyUser user = contextMgr.getClassObject(SpecifyUser.class); Agent agent = contextMgr.getClassObject(Agent.class); SpAppResourceDir dir = dirs.get(levelIndex); SpAppResource appRes = new SpAppResource(); appRes.initialize(); appRes.setName(fileName); appRes.setCreatedByAgent(agent); appRes.setSpecifyUser(user); if (dir.getId() == null) { dir.mergeTransientResourceAndViewSets(); } Pair<SpAppResource, String> retValues = checkForOverwriteOrNewName(dir, isSpReportRes ? repResourceName : fileName, isSpReportRes); if (retValues != null && retValues.first == null && retValues.second == null) { return; // Dialog was Cancelled } SpAppResource fndAppRes = retValues != null && retValues.first != null ? retValues.first : null; String newResName = retValues != null && retValues.second != null ? retValues.second : null; if (isReportRes) { if (fndAppRes != null) { if (isSpReportRes) { ReportsBaseTask.deleteReportAndResource(null, fndAppRes.getId()); } else { //XXX ??????????? if (fndAppRes.getSpAppResourceId() != null) { contextMgr.removeAppResourceSp(fndAppRes.getSpAppResourceDir(), fndAppRes); } } } /*else if (newResName == null) { return; }*/ if (isSpReportRes) { appRes = importSpReportZipResource(importFile, appRes, dir, newResName); if (appRes != null) { importedName = appRes.getName(); } } else { if (MainFrameSpecify.importJasperReport(importFile, false, newResName)) { importedName = importFile.getName(); } else { return; } } if (importedName != null) { CommandDispatcher.dispatch(new CommandAction(ReportsBaseTask.REPORTS, ReportsBaseTask.REFRESH, null)); CommandDispatcher.dispatch(new CommandAction(QueryTask.QUERY, QueryTask.REFRESH_QUERIES, null)); levelSelected(); } } else if (fndAppRes != null) // overriding { appRes.setMetaData(fndAppRes.getMetaData()); appRes.setDescription(fndAppRes.getDescription()); appRes.setFileName(fileName); appRes.setMimeType(appRes.getMimeType()); appRes.setName(fileName); appRes.setLevel(fndAppRes.getLevel()); } else if (!getMetaInformation(appRes, fileName)) { return; } if (!isReportRes) { appRes.setSpAppResourceDir(dir); dir.getSpAppResources().add(appRes); appRes.setDataAsString(data); contextMgr.saveResource(appRes); completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } setHasChanged(true); } catch (Exception e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, e); } } else if (selObj instanceof AppResourceIFace) { //if (isResourcePanel) resIndex++; AppResourceIFace fndAppRes = null; for (AppResourceIFace appRes : resources) { if (appRes == selObj) { fndAppRes = appRes; break; } } if (fndAppRes != null) { String importedFileName = fndAppRes.getFileName(); String fName = FilenameUtils.getName(importedFileName); String dbBaseName = FilenameUtils.getBaseName(fileName); //log.debug("["+fName+"]["+dbBaseName+"]"); boolean doOverwrite = true; if (!dbBaseName.equals(fName)) { String msg = getLocalizedMessage("RIE_OVRDE_MSG", dbBaseName, fName); doOverwrite = displayConfirm(getResourceString("RIE_OVRDE_TITLE"), msg, getResourceString("RIE_OVRDE"), getResourceString("CANCEL"), JOptionPane.QUESTION_MESSAGE); } if (doOverwrite) { fndAppRes.setDataAsString(data); contextMgr.saveResource(fndAppRes); completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } } else { UIRegistry.showError("Strange error - Couldn't resource."); } } } } if (importedName != null) { completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } if (hasChanged()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { okBtn.doClick(); } }); } } else { UIRegistry.showLocalizedError("FILE_NO_EXISTS", fullFileName); } } enableUI(); } }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * //from w ww .jav a 2 s . c om */ @SuppressWarnings("unchecked") protected void doSetVersion() { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g")); Vector<String> versionsList = new Vector<String>(); Hashtable<String, String> verToDateHash = new Hashtable<String, String>(); try { SimpleDateFormat mmddyyyy = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyy/MM/dd"); List<String> lines = FileUtils.readLines(rp.getDataFromWeb( UIRegistry.getResourceString("CGI_BASE_URL") + "/specifydownloads/specify6/alpha/versions.txt", false)); for (String line : lines) { String[] toks = line.split(","); if (toks.length > 2) { String ver = StringUtils.remove(toks[1].trim(), "Alpha "); versionsList.insertElementAt(ver, 0); String dateStr = toks[2].trim(); dateStr = StringUtils.replace(dateStr, ".", "/"); try { Date date = mmddyyyy.parse(dateStr); verToDateHash.put(ver, yyyymmdd.format(date)); } catch (Exception ex) { } } } versionsList.insertElementAt("Clear", 0); } catch (IOException ex) { ex.printStackTrace(); } final JList list = new JList(versionsList); final CustomDialog dlg = new CustomDialog(null, "Set Version", true, pb.getPanel()); pb.add(UIHelper.createLabel("Versions", SwingConstants.CENTER), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(list), cc.xy(1, 3)); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1); } } }); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { dlg.getOkBtn().doClick(); } } }); pb.setDefaultDialogBorder(); dlg.createUI(); dlg.getOkBtn().setEnabled(false); dlg.setVisible(true); if (!dlg.isCancelled()) { int inx = list.getSelectedIndex(); String version = (String) list.getSelectedValue(); if (version.equals("Clear")) { rp.setVersionDates(null, null, null); frame.setTitle(title); } else { String prevVersion = inx == list.getModel().getSize() - 1 ? null : (String) list.getModel().getElementAt(inx + 1); rp.setVersionDates(version, prevVersion, verToDateHash); frame.setTitle(title + " for " + version); } /*try { rp.process(doLocal ? new File("reg.dat") : rp.getDataFromWeb("SpReg.REGISTER_URL", true)); rp.processTracks(doLocal ? new File("track.dat") : rp.getDataFromWeb("StatsTrackerTask.URL", true)); rp.mergeStats(); } catch (IOException ex) { ex.printStackTrace(); }*/ } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * /*w w w . j a va2 s .co m*/ */ private void removeDataset() { Institution inst = iPadDBExporter.getCurrentInstitution(); List<Pair<String, String>> list = iPadCloud.getDatasetList(inst.getGuid()); if (list != null && list.size() > 0) { CellConstraints cc = new CellConstraints(); final JList<String> dsList = new JList<String>(new DSListModel(list)); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g")); pb.add(UIHelper.createI18NLabel("Choose a Dataset to remove"), cc.xy(1, 1)); pb.add(dsList, cc.xy(1, 3)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), "Remove Collection", true, pb.getPanel()); dsList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(!dsList.isSelectionEmpty()); } } }); dlg.setPreferredSize(new Dimension(300, 400)); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg, 300, 400); if (!dlg.isCancelled()) { String collectionGUID = list.get(dsList.getSelectedIndex()).first; if (StringUtils.isNotEmpty(collectionGUID)) { if (iPadCloud.removeDataSet(collectionGUID)) { enableRemoveDatasetBtn(); UIRegistry.writeTimedSimpleGlassPaneMsg("The dataset was removed."); } else { UIRegistry.writeTimedSimpleGlassPaneMsg("The dataset was not removed."); } } } return; } UIRegistry.showError("You do not have Datasets to remove."); // should not get here }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyAssignISOs.java
/** * @return//from ww w . j a v a 2 s. c o m */ @SuppressWarnings("rawtypes") public boolean buildAsyncOrig(final int earthId) { String sql = adjustSQL( "SELECT COUNT(*) FROM geography WHERE GeographyCode IS NOT NULL AND RankID = 100 AND GeographyTreeDefID = GEOTREEDEFID"); int numContinentsWithNames = BasicSQLUtils.getCountAsInt(sql); continentsCBX = createCheckBox("All Continents"); // I18N CellConstraints cc = new CellConstraints(); PanelBuilder pb1 = new PanelBuilder(new FormLayout("f:p:g", "p,4px,p,4px,p,8px")); countriesCBX = createCheckBox("All Countries"); stateCBX = createCheckBox("All States"); countiesCBX = createCheckBox("All Counties"); pb1.add(countriesCBX, cc.xy(1, 1)); pb1.add(stateCBX, cc.xy(1, 3)); //pb1.add(countiesCBX, cc.xy(1, 5)); allCountriesRB = new JRadioButton("Choose the Geography level to be processed"); //L18N singleCountryRB = new JRadioButton("Choose an individual Country"); btnGroup = new ButtonGroup(); btnGroup.add(this.allCountriesRB); btnGroup.add(this.singleCountryRB); if (numContinentsWithNames == 0) { continentsCBX.setEnabled(false); continentsCBX.setSelected(true); } countriesCBX.setEnabled(true); stateCBX.setEnabled(false); countiesCBX.setEnabled(false); countryIds.clear(); sql = "SELECT g.GeographyID, g.Name, g2.Name FROM geography g LEFT JOIN geography g2 ON g.ParentID = g2.GeographyID " + "WHERE g.Name IS NOT NULL && LENGTH(g.Name) > 0 AND g.RankID = 200 AND g.GeographyTreeDefID = GEOTREEDEFID ORDER BY g.Name"; sql = adjustSQL(sql); Vector<Object[]> rows = query(sql); Object[] titles = new Object[rows.size() + 1]; int i = 0; titles[i++] = "None"; // I18N countryIds.add(-1); for (Object[] r : rows) { countryIds.add((Integer) r[0]); String countryStr = (String) r[1]; String contStr = (String) r[2]; titles[i++] = countryStr != null ? (countryStr + " (" + contStr + ")") : countryStr; } PanelBuilder pb2 = new PanelBuilder(new FormLayout("8px,p,2px,f:p:g", "p,4px,p,8px")); spCountriesLbl = createFormLabel("Country"); // I18N spCountriesCmbx = createComboBox(titles); spStatesCBX = createCheckBox("States (Required)"); // I18N spCountiesCBX = createCheckBox("Counties"); // I18N pb2.add(spCountriesLbl, cc.xy(2, 1)); pb2.add(spCountriesCmbx, cc.xy(4, 1)); pb2.add(spStatesCBX, cc.xyw(1, 3, 4)); //pb2.add(spCountiesCBX, cc.xyw(1, 5, 4)); spCountriesCmbx.setSelectedIndex(0); spStatesCBX.setSelected(true); spStatesCBX.setEnabled(false); spCountiesCBX.setEnabled(false); String rowDef = createDuplicateJGoodiesDef("p", "4px", 8); PanelBuilder pb = new PanelBuilder(new FormLayout("16px,f:p:g", rowDef)); pb.addSeparator("Continents to be processed", cc.xyw(1, 1, 2)); pb.add(continentsCBX, cc.xyw(1, 3, 2)); pb.addSeparator("Countries to be processed", cc.xyw(1, 5, 2)); pb.add(allCountriesRB, cc.xyw(1, 7, 2)); pb.add(pb1.getPanel(), cc.xyw(2, 9, 1)); pb.add(singleCountryRB, cc.xyw(1, 11, 2)); pb.add(pb2.getPanel(), cc.xyw(2, 13, 1)); pb.add(createGeoStatsPanel(), cc.xyw(1, 15, 2)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) getTopWindow(), "ISO Code Processing", true, CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N dlg.setHelpContext("GeoCleanUpLevelChooser"); // Setup actions ChangeListener rbChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { radioSelected(dlg); } }; allCountriesRB.addChangeListener(rbChangeListener); singleCountryRB.addChangeListener(null); countriesCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { boolean isSel = countriesCBX.isSelected(); stateCBX.setEnabled(isSel); countiesCBX.setEnabled(false); if (!isSel) { stateCBX.setSelected(false); countiesCBX.setSelected(false); } calcGeoStats(); dlg.getOkBtn().setEnabled(isSel || spCountriesCmbx.getSelectedIndex() > 0); } }); stateCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { countiesCBX.setEnabled(stateCBX.isSelected()); if (!stateCBX.isSelected()) { countiesCBX.setSelected(false); } calcGeoStats(); } }); // Special spCountriesCmbx.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isSel = spCountriesCmbx.getSelectedIndex() > 0; spStatesCBX.setSelected(isSel); spCountiesCBX.setEnabled(isSel); if (!isSel) { spStatesCBX.setSelected(false); spCountiesCBX.setSelected(false); } calcGeoStats(); dlg.getOkBtn().setEnabled(isSel || countriesCBX.isSelected()); } }); spStatesCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { spCountiesCBX.setEnabled(stateCBX.isSelected()); calcGeoStats(); } }); allCountriesRB.setSelected(true); dlg.createUI(); dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Must be called after 'createUI' dlg.getOkBtn().setEnabled(false); // AUTO Don't show Dialog because it is automatically setting what to do centerAndShow(dlg); if (dlg.isCancelled()) { return false; } connectToDB(); if (true) // AUTO { doAllCountries = new boolean[] { countriesCBX.isSelected(), stateCBX.isSelected(), countiesCBX.isSelected(), false }; doInvCountry = new boolean[] { spCountriesCmbx.getSelectedIndex() > 0, spStatesCBX.isSelected(), spCountiesCBX.isSelected(), false }; doIndvCountryId = doInvCountry[0] ? countryIds.get(spCountriesCmbx.getSelectedIndex()) : null; } else { int indexOfUSA = getUnitedStatesIndex(titles); if (indexOfUSA == -1) { Vector<Object> nameList = new Vector<Object>(); Collections.addAll(nameList, titles); JList list = createList(nameList); JScrollPane sp = createScrollPane(list); pb = new PanelBuilder(new FormLayout("f:p:g", "p,8px,f:p:g")); pb.add(createLabel("Select the United States"), cc.xy(1, 1)); pb.add(sp, cc.xy(1, 3)); pb.setDefaultDialogBorder(); final CustomDialog askDlg = new CustomDialog((Frame) getTopWindow(), "Choose", true, CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N dlg.setHelpContext("GeoCleanUpLevelChooser"); centerAndShow(askDlg); if (!askDlg.isCancelled()) { indexOfUSA = list.getSelectedIndex(); } } doAllCountries = new boolean[] { true, false, false, false }; doInvCountry = new boolean[] { indexOfUSA > -1, true, false, false }; doIndvCountryId = doInvCountry[0] ? countryIds.get(indexOfUSA) : null; } // Check to see if it needs indexing. boolean shouldIndex = luceneSearch.shouldIndex(); if (shouldIndex) { frame = new ProgressFrame("Building Geography Authority..."); // I18N frame.getCloseBtn().setVisible(false); frame.turnOffOverAll(); frame.setDesc("Loading Geonames data..."); // I18N frame.pack(); frame.setSize(450, frame.getBounds().height + 10); UIHelper.centerAndShow(frame, 450, frame.getBounds().height + 10); luceneSearch.startIndexingProcessAsync(earthId, frame, new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { frame.setVisible(false); frame = null; if (((Boolean) e.getSource())) { GeographyAssignISOs.this.startTraversal(); } } }); } else { sql = "SELECT Name, geonameId, iso_alpha2 FROM countryinfo"; for (Object[] row : query(sql)) { countryInfo.add(new GeoSearchResultsItem((String) row[0], (Integer) row[1], (String) row[2])); } startTraversal(); } return true; }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * * @param advanceFocus//from w ww . ja v a 2 s. c o m */ protected void showDialog(final int advanceFocus) { final Vector<Integer> idListLocal = (Vector<Integer>) idList.clone(); final Vector<String> listLocal = (Vector<String>) list.clone(); final String enteredText = StringUtils.isEmpty(prevEnteredText) ? cachedPrevText : prevEnteredText; DefaultListModel<String> model = new DefaultListModel<String>(); if (doAddAddItem) { model.addElement(UIRegistry.getResourceString("TFWQ_ADD_LABEL")); //$NON-NLS-1$ } for (String val : list) { model.addElement(val); } final JList<String> listBox = new JList<String>(model); JPanel panel = new JPanel(new BorderLayout()); panel.add(createLabel(UIRegistry.getResourceString("TFWQ_CHOOSE_LABEL"), SwingConstants.CENTER), //$NON-NLS-1$ BorderLayout.NORTH); panel.add(UIHelper.createScrollPane(listBox, true), BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); // Had to do inner class in order to get it to select an item // before being shown class PopUpDialog extends CustomDialog { protected JList<String> pListBox; public PopUpDialog(final Frame frame, final boolean isModal, final Component contentPanel, JList<String> pListBoxArg) throws HeadlessException { super(frame, UIRegistry.getResourceString("TFWQ_CHOOSE_TITLE"), isModal, contentPanel); //$NON-NLS-1$ this.pListBox = pListBoxArg; initialize(); } public PopUpDialog(final Dialog dialog, final boolean isModal, final Component contentPanel, JList<String> pListBoxArg) throws HeadlessException { super(dialog, UIRegistry.getResourceString("TFWQ_CHOOSE_TITLE"), isModal, OK_BTN | CANCEL_BTN, //$NON-NLS-1$ contentPanel); this.pListBox = pListBoxArg; initialize(); } /** * */ protected void initialize() { pListBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (okBtn != null && pListBox != null) { okBtn.setEnabled(listBox.getSelectedIndex() != -1); } } } }); pListBox.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { okBtn.setEnabled(true); okBtn.doClick(); } } }); } @Override public void setVisible(final boolean visible) { if (visible) { listBox.setSelectedIndex(doAddAddItem ? 1 : 0); } super.setVisible(visible); } } hasNewText = false; Window mostRecent = UIRegistry.getMostRecentWindow(); CustomDialog dlg; if (mostRecent instanceof Dialog) { dlg = new PopUpDialog((Dialog) UIRegistry.getMostRecentWindow(), true, panel, listBox); } else { dlg = new PopUpDialog((Frame) UIRegistry.getMostRecentWindow(), true, panel, listBox); } dlg.setVisible(true); if (!dlg.isCancelled()) { int inx = listBox.getSelectedIndex(); boolean isDoingAdd = inx == 0 && doAddAddItem; inx = doAddAddItem ? inx - 1 : inx; if (!isDoingAdd && inx < idListLocal.size()) { selectedId = idListLocal.get(inx); setText(listLocal.get(inx)); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { transferFocus(advanceFocus); notifyListenersOfChange(isDoingAdd ? new AddItemEvent(enteredText) : listBox); } }); } else { setText(""); //$NON-NLS-1$ } }
From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java
/** * @return/*from ww w . j a v a 2s .c o m*/ * @throws SQLException */ public Pair<String, String> chooseTable(final String title, final String subTitle, final boolean doSp5DBs) throws SQLException { MySQLDMBSUserMgr mgr = new MySQLDMBSUserMgr(); Vector<DBNamePair> availPairs = new Vector<DBNamePair>(); if (mgr.connectToDBMS(itUsrPwd.first, itUsrPwd.second, hostName)) { BasicSQLUtils.setSkipTrackExceptions(true); //String sql = String.format("SELECT DISTINCT `COLUMNS`.TABLE_SCHEMA FROM `COLUMNS` WHERE `COLUMNS`.TABLE_NAME = '%s'", doSp5DBs ? "collectionobjectcatalog" : "taxon"); Connection conn = mgr.getConnection(); Vector<Object[]> dbNames = BasicSQLUtils.query(conn, "show databases"); for (Object[] row : dbNames) { String dbName = row[0].toString(); //System.out.print("Database Found ["+dbName+"] "); conn.setCatalog(dbName); boolean isSp5DB = false; Vector<Object[]> tables = BasicSQLUtils.query(conn, "show tables"); for (Object[] tblRow : tables) { String tableName = tblRow[0].toString(); if (tableName.equalsIgnoreCase("usysversion")) { isSp5DB = true; break; } } if ((!isSp5DB && doSp5DBs) || (isSp5DB && !doSp5DBs)) { continue; } // make all table names lowercase try { Integer count = BasicSQLUtils.getCount(conn, "select COUNT(*) FROM collection"); if (count == null) { for (Object[] tblRow : tables) { String tableName = tblRow[0].toString(); if (!tableName.equals(tableName.toLowerCase())) { BasicSQLUtils.update(conn, "RENAME TABLE " + tableName + " TO " + tableName.toLowerCase()); } } } } catch (Exception ex) { ex.printStackTrace(); } Vector<Object> tableDesc = BasicSQLUtils.querySingleCol(conn, "select CollectionName FROM collection"); if (tableDesc.size() > 0) { String collName = tableDesc.get(0).toString(); availPairs.add(new DBNamePair(collName, row[0].toString())); } } Collections.sort(availPairs, new Comparator<Pair<String, String>>() { @Override public int compare(Pair<String, String> o1, Pair<String, String> o2) { return o1.second.compareTo(o2.second); } }); mgr.close(); BasicSQLUtils.setSkipTrackExceptions(false); final JList list = new JList(availPairs); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g")); pb.add(UIHelper.createLabel(subTitle), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(list, true), cc.xy(1, 3)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog(null, title, true, pb.getPanel()); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1); } } }); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1); dlg.getOkBtn().doClick(); } } }); dlg.createUI(); dlg.pack(); Dimension d = dlg.getPreferredSize(); d.height = 700; dlg.setSize(d); UIHelper.centerAndShow(dlg); if (dlg.isCancelled()) { return null; } return namePairToConvert = (DBNamePair) list.getSelectedValue(); } return null; }
From source file:de.main.sessioncreator.DesktopApplication1View.java
public void getAreasBacgroundW(File f) { fileHelper.getAreas(f);/*w w w.j av a2 s .c o m*/ Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator(); while (it.hasNext()) { DefaultListModel dlm = new DefaultListModel(); JList list = new JList(dlm); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.getViewport().setView(list); Map.Entry en = it.next(); wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane); for (Object o : fileHelper.areaMap.get(en.getKey().toString())) { dlm.addElement(o); } MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList tabList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = tabList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = tabList.getModel().getElementAt(index); wizardtaChoosenAreas.append(o.toString() + "\n"); } } } }; list.addMouseListener(mouseListener); ListSelectionListener listListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable add button. wizardbtnAddAreas.setEnabled(false); } else { //Selection, enable the add button. wizardbtnAddAreas.setEnabled(true); } } } }; list.addListSelectionListener(listListener); } }