From: kiramt Date: Thu, 26 Jan 2017 11:40:39 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/develop' into features/JAL-2316 X-Git-Tag: Release_2_10_3b1~346^2~6 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=8358d28676df76a80e4b53af1d7ef2459e4f840b;hp=-c Merge remote-tracking branch 'origin/develop' into features/JAL-2316 --- 8358d28676df76a80e4b53af1d7ef2459e4f840b diff --combined resources/lang/Messages.properties index c33eccc,1352f0b..54835cc --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@@ -139,8 -139,7 +139,8 @@@ action.view_flanking_regions = Show fla label.view_flanking_regions = Show sequence data either side of the subsequences involved in this alignment label.structures_manager = Structures Manager label.nickname = Nickname: -label.url = URL: +label.url = URL +label.url\: = URL: label.input_file_url = Enter URL or Input File label.select_feature = Select feature label.name = Name @@@ -324,7 -323,7 +324,7 @@@ label.size = Size label.style = Style: label.calculating = Calculating.... label.modify_conservation_visibility = Modify conservation visibility - label.colour_residues_above_occurence = Colour residues above % occurence + label.colour_residues_above_occurrence = Colour residues above % occurrence label.set_this_label_text = set this label text label.sequences_from = Sequences from {0} label.successfully_loaded_file = Successfully loaded file {0} @@@ -412,6 -411,7 +412,6 @@@ label.couldnt_import_as_vamsas_session label.vamsas_document_import_failed = Vamsas Document Import Failed label.couldnt_locate = Couldn't locate {0} label.url_not_found = URL not found -label.no_link_selected = No link selected label.new_sequence_url_link = New sequence URL link label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view label.wrapped_view_no_edit = Wrapped view - no edit @@@ -1274,21 -1274,4 +1274,21 @@@ label.SEQUENCE_ID_no_longer_used = $SEQ label.SEQUENCE_ID_for_DB_ACCESSION1 = Please review your URL links in the 'Connections' tab of the Preferences window: label.SEQUENCE_ID_for_DB_ACCESSION2 = URL links using '$SEQUENCE_ID$' for DB accessions now use '$DB_ACCESSION$'. label.do_not_display_again = Do not display this message again +exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a custom url name +exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line +label.filter = Filter text: +action.customfilter = Custom only +action.showall = Show All +label.insert = Insert: +action.seq_id = $SEQUENCE_ID$ +action.db_acc = $DB_ACCESSION$ +label.primary = Double Click +label.inmenu = In Menu +label.id = ID +label.database = Database +label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option +label.edit_sequence_url_link = Edit sequence URL link +warn.name_cannot_be_duplicate = User-defined URL names must be unique and cannot be MIRIAM ids +label.invalid_name = Invalid Name ! label.output_seq_details = Output Sequence Details to list all database references +label.urllinks = Links diff --combined src/jalview/appletgui/APopupMenu.java index 8487104,bf985d7..7ca47b6 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@@ -36,7 -36,8 +36,8 @@@ import jalview.datamodel.SequenceGroup import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import jalview.io.DataSourceType; - import jalview.io.FileFormat; + import jalview.io.FileFormatI; + import jalview.io.FileFormats; import jalview.io.SequenceAnnotationReport; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@@ -92,8 -93,6 +93,6 @@@ public class APopupMenu extends java.aw protected MenuItem buriedColour = new MenuItem(); - protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem(); - protected MenuItem userDefinedColour = new MenuItem(); protected MenuItem PIDColour = new MenuItem(); @@@ -102,8 -101,14 +101,14 @@@ MenuItem noColourmenuItem = new MenuItem(); + protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem(); + + MenuItem modifyPID = new MenuItem(); + protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem(); + MenuItem modifyConservation = new MenuItem(); + final AlignmentPanel ap; MenuItem unGroupMenuItem = new MenuItem(); @@@ -196,7 -201,7 +201,7 @@@ Menu menu1 = new Menu(); public APopupMenu(AlignmentPanel apanel, final SequenceI seq, - Vector links) + List links) { // ///////////////////////////////////////////////////////// // If this is activated from the sequence panel, the user may want to @@@ -216,7 -221,7 +221,7 @@@ e.printStackTrace(); } - for (String ff : FileFormat.getWritableFormats(true)) + for (String ff : FileFormats.getInstance().getWritableFormats(true)) { MenuItem item = new MenuItem(ff); @@@ -247,7 -252,9 +252,9 @@@ if (sg.cs != null) { abovePIDColour.setState(sg.cs.getThreshold() > 0); + modifyPID.setEnabled(abovePIDColour.getState()); conservationMenuItem.setState(sg.cs.conservationApplied()); + modifyConservation.setEnabled(conservationMenuItem.getState()); } } } @@@ -588,6 -595,14 +595,14 @@@ { noColourmenuItem_actionPerformed(); } + else if (source == modifyConservation) + { + conservationMenuItem_itemStateChanged(); + } + else if (source == modifyPID) + { + abovePIDColour_itemStateChanged(); + } else if (source == unGroupMenuItem) { unGroupMenuItem_actionPerformed(); @@@ -789,7 -804,8 +804,8 @@@ // now returns a full copy of sequence data // TODO consider using getSequenceSelection instead here - FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); + FileFormatI fileFormat = FileFormats.getInstance().forName( + e.getActionCommand()); cap.setText(new AppletFormatAdapter().formatSequences(fileFormat, ap.av.getShowJVSuffix(), ap, true)); @@@ -900,6 -916,14 +916,14 @@@ nucleotideMenuItem.addActionListener(this); conservationMenuItem.addItemListener(this); abovePIDColour.addItemListener(this); + modifyPID.setLabel(MessageManager + .getString("label.modify_identity_threshold")); + modifyPID.addActionListener(this); + modifyConservation.setLabel(MessageManager + .getString("label.modify_conservation_threshold")); + modifyPID.setEnabled(abovePIDColour.getState()); + modifyConservation.setEnabled(conservationMenuItem.getState()); + modifyConservation.addActionListener(this); colourMenu.setLabel(MessageManager.getString("label.group_colour")); showBoxes.setLabel(MessageManager.getString("action.boxes")); showBoxes.setState(true); @@@ -954,8 -978,10 +978,10 @@@ colourMenu.add(nucleotideMenuItem); colourMenu.add(userDefinedColour); colourMenu.addSeparator(); - colourMenu.add(abovePIDColour); colourMenu.add(conservationMenuItem); + colourMenu.add(modifyConservation); + colourMenu.add(abovePIDColour); + colourMenu.add(modifyPID); noColourmenuItem.setLabel(MessageManager.getString("label.none")); noColourmenuItem.addActionListener(this); @@@ -992,7 -1018,7 +1018,7 @@@ BLOSUM62Colour.setLabel("BLOSUM62"); BLOSUM62Colour.addActionListener(this); conservationMenuItem.setLabel(MessageManager - .getString("label.conservation")); + .getString("action.by_conservation")); editMenu.add(copy); copy.addActionListener(this); @@@ -1117,11 -1143,11 +1143,11 @@@ else // remove PIDColouring { + SliderPanel.hidePIDSlider(); sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus()); } - + modifyPID.setEnabled(abovePIDColour.getState()); refresh(); - } protected void userDefinedColour_actionPerformed() @@@ -1176,9 -1202,10 +1202,10 @@@ else // remove ConservationColouring { + SliderPanel.hideConservationSlider(); sg.cs.setConservation(null); } - + modifyConservation.setEnabled(conservationMenuItem.getState()); refresh(); } diff --combined src/jalview/gui/Desktop.java index 5363999,0321662..dc16a57 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@@ -20,6 -20,7 +20,6 @@@ */ package jalview.gui; -import static jalview.util.UrlConstants.EMBLEBI_STRING; import static jalview.util.UrlConstants.SEQUENCE_ID; import jalview.api.AlignViewportI; @@@ -30,6 -31,7 +30,7 @@@ import jalview.io.DataSourceType import jalview.io.FileFormat; import jalview.io.FileFormatException; import jalview.io.FileFormatI; + import jalview.io.FileFormats; import jalview.io.FileLoader; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; @@@ -37,14 -39,11 +38,14 @@@ import jalview.io.JalviewFileView import jalview.jbgui.GSplitFrame; import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; +import jalview.urls.IdOrgSettings; import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ParamManager; +import jalview.ws.utils.UrlDownloadClient; import java.awt.BorderLayout; import java.awt.Color; @@@ -79,7 -78,6 +80,7 @@@ import java.beans.PropertyChangeListene import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Hashtable; @@@ -394,8 -392,6 +395,8 @@@ public class Desktop extends jalview.jb showNews.setVisible(false); + getIdentifiersOrgData(); + checkURLLinks(); this.addWindowListener(new WindowAdapter() @@@ -529,29 -525,6 +530,29 @@@ }); } + public void getIdentifiersOrgData() + { + // Thread off the identifiers fetcher + addDialogThread(new Runnable() + { + @Override + public void run() + { + Cache.log.debug("Downloading data from identifiers.org"); + UrlDownloadClient client = new UrlDownloadClient(); + try + { + client.download(IdOrgSettings.getUrl(), + IdOrgSettings.getDownloadLocation()); + } catch (IOException e) + { + Cache.log.debug("Exception downloading identifiers.org data" + + e.getMessage()); + } + } + }); + } + @Override protected void showNews_actionPerformed(ActionEvent e) { @@@ -1053,20 -1026,21 +1054,21 @@@ Cache.setProperty("LAST_DIRECTORY", chooser .getSelectedFile().getParent()); - FileFormatI format = null; - FileFormatI selectedFormat = chooser.getSelectedFormat(); - if (FileFormat.Jalview.equals(selectedFormat)) - { - format = FileFormat.Jalview; - } - else + FileFormatI format = chooser.getSelectedFormat(); + + /* + * Call IdentifyFile to verify the file contains what its extension implies. + * Skip this step for dynamically added file formats, because + * IdentifyFile does not know how to recognise them. + */ + if (FileFormats.getInstance().isIdentifiable(format)) { try { format = new IdentifyFile().identify(choice, DataSourceType.FILE); } catch (FileFormatException e) { - // format is null + // format = null; //?? } } @@@ -1557,8 -1531,8 +1559,8 @@@ @Override public void saveState_actionPerformed(ActionEvent e) { - JalviewFileChooser chooser = new JalviewFileChooser( - Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project"); + JalviewFileChooser chooser = new JalviewFileChooser("jvp", + "Jalview Project"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.save_state")); @@@ -2211,8 -2185,8 +2213,8 @@@ { if (v_client != null) { - JalviewFileChooser chooser = new JalviewFileChooser( - Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ + // TODO: VAMSAS DOCUMENT EXTENSION is VDJ + JalviewFileChooser chooser = new JalviewFileChooser("vdj", "Vamsas Document"); chooser.setFileView(new JalviewFileView()); @@@ -2316,8 -2290,7 +2318,8 @@@ { // check what the actual links are - if it's just the default don't // bother with the warning - Vector links = Preferences.sequenceURLLinks; + List links = Preferences.sequenceUrlLinks + .getLinksForMenu(); // only need to check links if there is one with a // SEQUENCE_ID which is not the default EMBL_EBI link @@@ -2327,8 -2300,7 +2329,8 @@@ while (li.hasNext()) { String link = li.next(); - if (link.contains(SEQUENCE_ID) && !link.equals(EMBLEBI_STRING)) + if (link.contains(SEQUENCE_ID) + && !link.equals(UrlConstants.DEFAULT_STRING)) { check = true; int barPos = link.indexOf("|"); diff --combined src/jalview/gui/Preferences.java index fbf31ff,422745a..a61279a --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@@ -20,6 -20,11 +20,6 @@@ */ package jalview.gui; -import static jalview.util.UrlConstants.DB_ACCESSION; -import static jalview.util.UrlConstants.EMBLEBI_STRING; -import static jalview.util.UrlConstants.SEQUENCE_ID; -import static jalview.util.UrlConstants.SRS_STRING; - import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; import jalview.gui.Help.HelpId; @@@ -30,18 -35,12 +30,18 @@@ import jalview.io.JalviewFileView import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; import jalview.schemes.ColourSchemeProperty; +import jalview.urls.UrlLinkTableModel; +import jalview.urls.api.UrlProviderFactoryI; +import jalview.urls.api.UrlProviderI; +import jalview.urls.desktop.DesktopUrlProviderFactory; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.UrlConstants; import jalview.ws.sifts.SiftsSettings; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; @@@ -50,24 -49,14 +50,24 @@@ import java.awt.event.MouseEvent import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.StringTokenizer; -import java.util.Vector; import javax.help.HelpSetException; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JPanel; +import javax.swing.ListSelectionModel; +import javax.swing.RowFilter; +import javax.swing.RowSorter; +import javax.swing.SortOrder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; import ext.edu.ucsf.rbvi.strucviz2.StructureManager; @@@ -113,9 -102,7 +113,9 @@@ public class Preferences extends GPrefe * Holds name and link separated with | character. Sequence ID must be * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$ */ - public static Vector sequenceURLLinks; + public static UrlProviderI sequenceUrlLinks; + + public static UrlLinkTableModel dataModel; /** * Holds name and link separated with | character. Sequence IDS and Sequences @@@ -128,23 -115,40 +128,23 @@@ public static List groupURLLinks; static { - String string = Cache.getDefault("SEQUENCE_LINKS", EMBLEBI_STRING); - sequenceURLLinks = new Vector(); - - try + // get links selected to be in the menu (SEQUENCE_LINKS) + // and links entered by the user but not selected (STORED_LINKS) + String inMenuString = Cache.getDefault("SEQUENCE_LINKS", ""); + String notInMenuString = Cache.getDefault("STORED_LINKS", ""); + String defaultUrl = Cache.getDefault("DEFAULT_URL", + UrlConstants.DEFAULT_LABEL); + + // if both links lists are empty, add the DEFAULT_URL link + // otherwise we assume the default link is in one of the lists + if (inMenuString.isEmpty() && notInMenuString.isEmpty()) { - StringTokenizer st = new StringTokenizer(string, "|"); - while (st.hasMoreElements()) - { - String name = st.nextToken(); - String url = st.nextToken(); - // check for '|' within a regex - int rxstart = url.indexOf("$" + DB_ACCESSION + "$"); - if (rxstart == -1) - { - rxstart = url.indexOf("$" + SEQUENCE_ID + "$"); - } - while (rxstart == -1 && url.indexOf("/=$") == -1) - { - url = url + "|" + st.nextToken(); - } - sequenceURLLinks.addElement(name + "|" + url); - } - } catch (Exception ex) - { - System.out.println(ex + "\nError parsing sequence links"); - } - { - // upgrade old SRS link - int srsPos = sequenceURLLinks.indexOf(SRS_STRING); - if (srsPos > -1) - { - sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos); - } + inMenuString = UrlConstants.DEFAULT_STRING; } + UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl, + inMenuString, notInMenuString); + sequenceUrlLinks = factory.createUrlProvider(); + dataModel = new UrlLinkTableModel(sequenceUrlLinks); /** * TODO: reformulate groupURL encoding so two or more can be stored in the @@@ -154,6 -158,8 +154,6 @@@ groupURLLinks = new ArrayList(); } - Vector nameLinks, urlLinks; - JInternalFrame frame; DasSourceBrowser dasSource; @@@ -337,128 -343,18 +337,128 @@@ /* * Set Connections tab defaults */ - nameLinks = new Vector(); - urlLinks = new Vector(); - for (int i = 0; i < sequenceURLLinks.size(); i++) + + // set up sorting + linkUrlTable.setModel(dataModel); + final TableRowSorter sorter = new TableRowSorter<>( + linkUrlTable.getModel()); + linkUrlTable.setRowSorter(sorter); + List sortKeys = new ArrayList<>(); + + UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel(); + sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(), + SortOrder.DESCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(), + SortOrder.DESCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getNameColumn(), + SortOrder.ASCENDING)); + + sorter.setSortKeys(sortKeys); + sorter.sort(); + + // set up filtering + ActionListener onReset; + onReset = new ActionListener() { - String link = sequenceURLLinks.elementAt(i).toString(); - nameLinks.addElement(link.substring(0, link.indexOf("|"))); - urlLinks.addElement(link.substring(link.indexOf("|") + 1)); - } + @Override + public void actionPerformed(ActionEvent e) + { + filterTB.setText(""); + sorter.setRowFilter(RowFilter.regexFilter("")); + } + + }; + doReset.addActionListener(onReset); + + // filter to display only custom urls + final RowFilter customUrlFilter = new RowFilter() + { + @Override + public boolean include( + Entry entry) + { + return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry); + } + }; + + final TableRowSorter customSorter = new TableRowSorter<>( + linkUrlTable.getModel()); + customSorter.setRowFilter(customUrlFilter); + + ActionListener onCustomOnly; + onCustomOnly = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + filterTB.setText(""); + sorter.setRowFilter(customUrlFilter); + } + }; + userOnly.addActionListener(onCustomOnly); + + filterTB.getDocument().addDocumentListener(new DocumentListener() + { + String caseInsensitiveFlag = "(?i)"; - updateLinkData(); + @Override + public void changedUpdate(DocumentEvent e) + { + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + + filterTB.getText())); + } + + @Override + public void removeUpdate(DocumentEvent e) + { + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + + filterTB.getText())); + } + + @Override + public void insertUpdate(DocumentEvent e) + { + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + + filterTB.getText())); + } + }); + + // set up list selection functionality + linkUrlTable.getSelectionModel().addListSelectionListener( + new UrlListSelectionHandler()); + + // set up radio buttons + int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getPrimaryColumn(); + String onClickName = linkUrlTable.getColumnName(onClickCol); + linkUrlTable.getColumn(onClickName).setCellRenderer( + new RadioButtonRenderer()); + linkUrlTable.getColumn(onClickName) + .setCellEditor(new RadioButtonEditor()); + + // get boolean columns and resize those to min possible + for (int column = 0; column < linkUrlTable.getColumnCount(); column++) + { + if (linkUrlTable.getModel().getColumnClass(column) + .equals(Boolean.class)) + { + TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn( + column); + int preferredWidth = tableColumn.getMinWidth(); + + TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0, + column); + Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column); + int cwidth = c.getPreferredSize().width + + linkUrlTable.getIntercellSpacing().width; + preferredWidth = Math.max(preferredWidth, cwidth); + + tableColumn.setPreferredWidth(preferredWidth); + } + } useProxy.setSelected(Cache.getDefault("USE_PROXY", false)); + useProxy_actionPerformed(); // make sure useProxy is correctly initialised proxyServerTB.setEnabled(useProxy.isSelected()); proxyPortTB.setEnabled(useProxy.isSelected()); proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", "")); @@@ -652,32 -548,28 +652,32 @@@ jalview.util.BrowserLauncher.resetBrowser(); - if (nameLinks.size() > 0) + // save user-defined and selected links + String menuLinks = sequenceUrlLinks.writeUrlsAsString(true); + if (menuLinks.isEmpty()) + { + Cache.applicationProperties.remove("SEQUENCE_LINKS"); + } + else { - StringBuffer links = new StringBuffer(); - sequenceURLLinks = new Vector(); - for (int i = 0; i < nameLinks.size(); i++) - { - sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|" - + urlLinks.elementAt(i)); - links.append(sequenceURLLinks.elementAt(i).toString()); - links.append("|"); - } - // remove last "|" - links.setLength(links.length() - 1); Cache.applicationProperties.setProperty("SEQUENCE_LINKS", - links.toString()); + menuLinks.toString()); + } + + String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false); + if (nonMenuLinks.isEmpty()) + { + Cache.applicationProperties.remove("STORED_LINKS"); } else { - Cache.applicationProperties.remove("SEQUENCE_LINKS"); - sequenceURLLinks.clear(); + Cache.applicationProperties.setProperty("STORED_LINKS", + nonMenuLinks.toString()); } + Cache.applicationProperties.setProperty("DEFAULT_URL", + sequenceUrlLinks.getPrimaryUrlId()); + Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected())); @@@ -809,7 -701,7 +809,7 @@@ if (format != null) { Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", - format.toString()); + format.getName()); } startupFileTextfield.setText(chooser.getSelectedFile() .getAbsolutePath()); @@@ -858,6 -750,7 +858,6 @@@ @Override public void newLink_actionPerformed(ActionEvent e) { - GSequenceLink link = new GSequenceLink(); boolean valid = false; while (!valid) @@@ -868,18 -761,10 +868,18 @@@ { if (link.checkValid()) { - nameLinks.addElement(link.getName()); - urlLinks.addElement(link.getURL()); - updateLinkData(); - valid = true; + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName())) + { + ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( + link.getName(), link.getURL()); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@@ -894,46 -779,36 +894,46 @@@ { GSequenceLink link = new GSequenceLink(); - int index = linkNameList.getSelectedIndex(); + int index = linkUrlTable.getSelectedRow(); if (index == -1) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JvOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Edit with no row selected in linkUrlTable"); return; } - link.setName(nameLinks.elementAt(index).toString()); - link.setURL(urlLinks.elementAt(index).toString()); + int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getNameColumn(); + int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getUrlColumn(); + String oldName = linkUrlTable.getValueAt(index, nameCol).toString(); + link.setName(oldName); + link.setURL(linkUrlTable.getValueAt(index, urlCol).toString()); boolean valid = false; while (!valid) { - if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, - MessageManager.getString("label.new_sequence_url_link"), + MessageManager.getString("label.edit_sequence_url_link"), JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION) { if (link.checkValid()) { - nameLinks.setElementAt(link.getName(), index); - urlLinks.setElementAt(link.getURL(), index); - updateLinkData(); - valid = true; + if ((oldName.equals(link.getName())) + || (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName()))) + { + linkUrlTable.setValueAt(link.getName(), index, nameCol); + linkUrlTable.setValueAt(link.getURL(), index, urlCol); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } - else { break; @@@ -944,24 -819,26 +944,24 @@@ @Override public void deleteLink_actionPerformed(ActionEvent e) { - int index = linkNameList.getSelectedIndex(); + int index = linkUrlTable.getSelectedRow(); + int modelIndex = -1; if (index == -1) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JvOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Delete with no row selected in linkUrlTable"); return; } - nameLinks.removeElementAt(index); - urlLinks.removeElementAt(index); - updateLinkData(); - } + else + { + modelIndex = linkUrlTable.convertRowIndexToModel(index); + } - void updateLinkData() - { - linkNameList.setListData(nameLinks); - linkURLList.setListData(urlLinks); + // make sure we use the model index to delete, and not the table index + ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex); } + @Override public void defaultBrowser_mouseClicked(MouseEvent e) { @@@ -1178,45 -1055,4 +1178,45 @@@ return name.hashCode() + code.hashCode(); } } + + private class UrlListSelectionHandler implements ListSelectionListener + { + + @Override + public void valueChanged(ListSelectionEvent e) + { + ListSelectionModel lsm = (ListSelectionModel) e.getSource(); + + int index = lsm.getMinSelectionIndex(); + if (index == -1) + { + // no selection, so disable delete/edit buttons + editLink.setEnabled(false); + deleteLink.setEnabled(false); + return; + } + int modelIndex = linkUrlTable.convertRowIndexToModel(index); + + // enable/disable edit and delete link buttons + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowDeletable(modelIndex)) + { + deleteLink.setEnabled(true); + } + else + { + deleteLink.setEnabled(false); + } + + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowEditable(modelIndex)) + { + editLink.setEnabled(true); + } + else + { + editLink.setEnabled(false); + } + } +} }