Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
""));
final FeatureEdit fe = new FeatureEdit(selection_feature, entry_group,
selection, goto_event_source, edit_frame);
edit_frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
fe.stopListening();
edit_frame.dispose();
}
});
if(cancel_listener != null)
fe.addCancelActionListener(cancel_listener);
if(apply_listener != null)
fe.addApplyActionListener(apply_listener);
edit_frame.getContentPane().add(fe);
edit_frame.pack();
Utilities.centreFrame(edit_frame);
edit_frame.setVisible(true);
return true;
}
}
/**
* Create a new EntryEdit component that contains only the selected
* sequence and the features in the selected range.
**/
private void editSubSequence()
{
if(getSelection().isEmpty())
new MessageDialog(getParentFrame(), "nothing selected");
final Range range = getSelection().getSelectionRange();
final EntryGroup new_entry_group = getEntryGroup().truncate(range);
new EntryEdit(new_entry_group).setVisible(true);
}
/**
* Open a EntryHeaderEdit window for the default entry.
**/
private void editHeader()
{
final Entry default_entry = getEntryGroup().getDefaultEntry();
if(default_entry == null)
{
final String message = "there is no default entry";
new MessageDialog(getParentFrame(), message);
}
else
{
if(default_entry.isReadOnly())
{
new MessageDialog(getParentFrame(),
"the default entry is read-only " +
"- cannot continue");
new EntryHeaderEdit(entry_group, default_entry);
}
}
/**
* Merge the selected features into one Feature. If there are selected
* segments then the owning Feature of each segment will be the Feature
* that is merged. This method will create a new Feature.
* @param frame The JFrame to use for MessageDialog components.
* @param selection The Selection containing the features to merge.
* @param entry_group Used to get the ActionController for calling
* startAction() and endAction().
**/
protected static void mergeFeatures(final JFrame frame,
final Selection selection,
final EntryGroup entry_group)
{
try
{
entry_group.getActionController().startAction();
if(!checkForSelectionFeatures(frame, selection, 10,
"really merge all (>10) " + "selected features?"))
final FeatureVector features_to_merge = selection.getAllFeatures();
if(features_to_merge.size() < 2)
{
new MessageDialog(frame,
"nothing to merge - select more than one feature");
final Feature merge_feature = features_to_merge.elementAt(0);
for(int i = 1; i < features_to_merge.size(); ++i)
{
final Feature this_feature = features_to_merge.elementAt(i);
if(this_feature.isForwardFeature() !=
merge_feature.isForwardFeature())
{
new MessageDialog(frame,
"all the features in a merge must be on the " +
"same strand");
if(!this_feature.getKey().equals(merge_feature.getKey()))
{
new MessageDialog(frame,
"all the features in a merge must have the " +
"same key");
if(Options.getOptions().isNoddyMode())
{
new YesNoDialog(frame, "Are you sure you want to merge the selected " +
"features?");
if(!dialog.getResult())
//
// GFF merge
if(merge_feature.getEmblFeature() instanceof GFFStreamFeature)
{
if(!merge_feature.getKey().equals(DatabaseDocument.EXONMODEL) &&
!merge_feature.getKey().equals("pseudogenic_exon"))
{
new MessageDialog(frame,"The features in a merge should be "+
DatabaseDocument.EXONMODEL+
" or pseudogenic_exon features");
return;
}
gffMergeFeatures(features_to_merge, merge_feature,
selection, entry_group);
try
{
new_feature = merge_feature.duplicate();
}
catch(ReadOnlyException e)
{
final String message =
"one or more of the features is read-only or is in a " +
"read-only entry - cannot continue";
new MessageDialog(frame, message);
for(int i = 1; i < features_to_merge.size(); ++i)
{
final Feature this_feature = features_to_merge.elementAt(i);
final QualifierVector qualifiers = this_feature.getQualifiers();
for(int j = 0; j < qualifiers.size(); ++j)
{
final Qualifier this_qualifier = (Qualifier)qualifiers.elementAt(j);
try
{
new_feature.addQualifierValues(this_qualifier);
}
catch(EntryInformationException e)
{
try
{
new_feature.removeFromEntry();
}
catch(ReadOnlyException _)
{
// give up ...
}
final String message =
"destination entry does not support all the qualifiers " +
"needed by " + this_feature.getIDString();
new MessageDialog(frame, message);
}
catch(ReadOnlyException e)
{
final String message = "the new feature is read-only so " +
"some qualifiers have been lost";
new MessageDialog(frame, message);
final FeatureSegmentVector segments = this_feature.getSegments();
for(int j = 0; j < segments.size(); ++j)
{
segments.elementAt(j);
final Range this_range = this_segment.getRawRange();
try
{
new_feature.addSegment(this_range);
}
catch(ReadOnlyException e)
{
final String message =
"merging failed because the entry is read-only";
new MessageDialog(frame, message);
try
{
new_feature.removeFromEntry();
catch(ReadOnlyException _) {}
}
}
}
// this is set to true when a merge is done in the next (inner) loop
boolean keep_looping = true;
// this is a bit inefficient, but there aren't normally many segments
LOOP:
while(keep_looping)
{
new_feature.getSegments();
keep_looping = false;
// now merge overlapping ranges
for(int i = 0; i < feature_segments.size() - 1; ++i)
{
feature_segments.elementAt(i);
final MarkerRange this_range = this_segment.getMarkerRange();
feature_segments.elementAt(i + 1);
final MarkerRange next_range = next_segment.getMarkerRange();
if(this_range.overlaps(next_range) &&
this_segment.getFrameID() == next_segment.getFrameID())
{
try
{
this_range.combineRanges(next_range, false).getRawRange();
new_feature.addSegment(new_range);
new_feature.removeSegment(this_segment);
new_feature.removeSegment(next_segment);
}
catch(ReadOnlyException e)
{
final String message =
"merging failed because the entry is read-only";
new MessageDialog(frame, message);
}
catch(LastSegmentException e)
{
throw new Error("internal error - tried to remove " +
"last segment: " + e);
if(Options.getOptions().isNoddyMode())
{
new YesNoDialog(frame, "delete old features?");
delete_old_features = delete_old_dialog.getResult();
}
else
if(delete_old_features)
{
if(getReadOnlyFeatures(features_to_merge).size() > 0)
new MessageDialog(frame, "deletion failed because the features " +
"are read-only");
else
{
for(int i = 0; i < features_to_merge.size(); ++i)
{
try
{
features_to_merge.elementAt(i).removeFromEntry();
}
catch(ReadOnlyException e)
{
new MessageDialog(frame, "deletion failed one or more of the " +
"features are read-only");
selection.set(new_feature);
}
finally
{
entry_group.getActionController().endAction();
/**
* Merge features / gene model - creating gene model if not already present
* @param features_to_merge
* @param merge_feature
* @param selection
* @param entry_group
*/
public static void gffMergeFeatures(final FeatureVector features_to_merge,
final Feature merge_feature,
final Selection selection,
final EntryGroup entry_group)
{
try
{
java.util.List geneModels = getGeneModels(features_to_merge);
if(geneModels.size() == 0)
final Location geneLocation = new Location(selection.getSelectionRange());
final String parentId = GeneUtils.getUniqueName(
merge_feature.getEmblFeature())+":gene";
final QualifierVector qualifiers = new QualifierVector();
qualifiers.setQualifier(new Qualifier("ID", parentId));
// create gene
final Key key;
if(merge_feature.getKey().getKeyString().equals("pseudogenic_exon"))
key = new Key("pseudogene");
else
key = new Key("gene");
Feature parentGene = merge_feature.getEntry().createFeature(key,
geneLocation, qualifiers);
chadoGene = new ChadoCanonicalGene();
chadoGene.setGene(parentGene.getEmblFeature());
((uk.ac.sanger.artemis.io.GFFStreamFeature)
(parentGene.getEmblFeature())).setChadoGene(chadoGene);
// create transcript
Feature transcript = GeneViewerPanel.createTranscript(chadoGene, entry_group);
((uk.ac.sanger.artemis.io.GFFStreamFeature)
(transcript.getEmblFeature())).setChadoGene(chadoGene);
transcriptId = GeneUtils.getUniqueName(transcript.getEmblFeature());
parentQualifier = new Qualifier("Parent", transcriptId);
merge_feature.setQualifier(parentQualifier);
}
else
{
boolean isMultipleTranscript = false;
for(int i=0; i<geneModels.size(); i++)
{
if(((ChadoCanonicalGene)geneModels.get(i)).getTranscripts().size() != 1)
isMultipleTranscript = true;
}
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
if(features_to_merge.size() > 2 ||
geneModels.size() > 2 ||
isMultipleTranscript)
{
JOptionPane.showMessageDialog(null,
"This option cannot be used to merge more than 2 gene models.\n"+
"Select two exons in two gene models to be merged.\n"+
"The gene models must have just one transcript.");
return;
}
logger4j.debug("Found "+geneModels.size()+" gene models for merging");
if(geneModels.size() == 2)
{
parentQualifier = merge_feature.getQualifierByName("Parent");
transcriptId = (String)parentQualifier.getValues().get(0);
chadoGene = ((GFFStreamFeature)merge_feature.getEmblFeature()).getChadoGene();
final String chadoGeneName = chadoGene.getGeneUniqueName();
for(int i=0; i<geneModels.size(); i++)
{
final ChadoCanonicalGene thisChadoGene = (ChadoCanonicalGene)geneModels.get(i);
if(!thisChadoGene.equals(chadoGeneName))
chadoGene2 = thisChadoGene;
}
}
else
{
chadoGene = (ChadoCanonicalGene)geneModels.get(0);
transcriptId = GeneUtils.getUniqueName(
(uk.ac.sanger.artemis.io.Feature)chadoGene.getTranscripts().get(0));
parentQualifier = new Qualifier("Parent", transcriptId);
merge_feature.setQualifier(parentQualifier);
}
// TODO - merge transcript / peptide qualifiers into chadoGene ??
}
final RangeVector ranges = new RangeVector();
java.util.Hashtable id_range_store =
((GFFStreamFeature)merge_feature.getEmblFeature()).getSegmentRangeStore();
for(int i=1; i< features_to_merge.size(); i++)
{
final Feature this_feature = features_to_merge.elementAt(i);
final FeatureSegmentVector segments = this_feature.getSegments();
for(int j = 0; j < segments.size(); ++j)
{
final FeatureSegment this_segment = segments.elementAt(j);
ranges.add(this_segment.getRawRange());
}
}
for(int i=0; i<features_to_merge.size(); i++)
{
final Feature this_feature = features_to_merge.elementAt(i);
this_feature.getEntry().remove(this_feature, false);
//uk.ac.sanger.artemis.chado.ChadoTransactionManager.addSegments = false;
for(int i = 0; i < ranges.size(); i++)
{
final Range range = (Range)ranges.get(i);
final String segId = chadoGene.autoGenerateSplicedFeatureName(transcriptId);
id_range_store.put(segId,range);
((GFFStreamFeature)merge_feature.getEmblFeature()).setSegmentRangeStore(id_range_store);
//uk.ac.sanger.artemis.chado.ChadoTransactionManager.addSegments = true;
final String ID = ((GFFStreamFeature)merge_feature.getEmblFeature()).getSegmentID(
final Qualifier qualifier = new Qualifier("ID", ID);
merge_feature.getEmblFeature().setQualifier(qualifier);
chadoGene.addSplicedFeatures(transcriptId, merge_feature.getEmblFeature(), true);
((GFFStreamFeature)merge_feature.getEmblFeature()).setChadoGene(chadoGene);
if(chadoGene2 != null)
{
logger4j.debug("Now DELETE "+chadoGene2.getGeneUniqueName());
GeneUtils.deleteAllFeature((Feature)chadoGene2.getGene().getUserData(), chadoGene2);
}
if(chadoGene != null)
{
logger4j.debug("Check gene boundaries of: "+chadoGene.getGeneUniqueName());
GeneUtils.checkGeneBoundary(chadoGene);
}
}
catch(ReadOnlyException e)
{
final String message = "one or more of the features is read-only or is in a "
+ "read-only entry - cannot continue";
new MessageDialog(null, message);
return;
}
catch(InvalidRelationException ire){ ire.printStackTrace(); }
catch(EntryInformationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(OutOfRangeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
/**
* Get the chado gene models for a list of features
* @param features
* @return
*/
private static java.util.List getGeneModels(final FeatureVector features)
{
final java.util.List geneModels = new Vector();
final java.util.List geneModelNames = new Vector();
for(int i=0; i< features.size(); i++)
{
if(features.elementAt(i).getEmblFeature() instanceof GFFStreamFeature)
{
final GFFStreamFeature this_feature =
(GFFStreamFeature)features.elementAt(i).getEmblFeature();
if(this_feature.getChadoGene() != null)
{
final String this_name =
this_feature.getChadoGene().getGeneUniqueName();
if(!geneModelNames.contains(this_name))
{
geneModels.add(this_feature.getChadoGene());
geneModelNames.add(this_name);
}
}
}
}
return geneModels;
}
/**
* If the selection contains exactly two segments and those segments are
* adjacent in the same feature, split the feature into two pieces. The
* orignal feature is truncated and a new feature is created. The
* qualifiers of the old feature are copied to new feature.
* @param frame The JFrame to use for MessageDialog components.
* @param selection The Selection containing the segments to unmerge.
* @param entry_group Used to get the ActionController for calling
* startAction() and endAction().
**/
private static void unmergeFeature(final JFrame frame,
entry_group.getActionController ().startAction ();
final FeatureSegmentVector selected_segments =
selection.getSelectedSegments ();
final String message =
"you need to select exactly two exons use unmerge";
return;
}
FeatureSegment first_segment = selected_segments.elementAt (0);
FeatureSegment second_segment = selected_segments.elementAt (1);
if(first_segment.getFeature () != second_segment.getFeature ())
{
final String message =
"you need to select two exons from the same feature to use unmerge";
new MessageDialog (frame, message);
return;
}
final Feature segment_feature = first_segment.getFeature ();
final FeatureSegmentVector all_feature_segments =
segment_feature.getSegments ();
int index_of_first_segment =
all_feature_segments.indexOf (first_segment);
int index_of_second_segment =
all_feature_segments.indexOf (second_segment);
if(index_of_first_segment - index_of_second_segment < -1 ||
index_of_first_segment - index_of_second_segment > 1)
{
final String message =
"you need to select two adjacent exons to use unmerge";
new MessageDialog (frame, message);
return;
}
if(index_of_second_segment < index_of_first_segment)
{
// swap the segments for consistency
final FeatureSegment temp_segment = first_segment;
final int temp_segment_index = index_of_first_segment;
first_segment = second_segment;
index_of_first_segment = index_of_second_segment;
second_segment = temp_segment;
index_of_second_segment = temp_segment_index;
}
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
final Feature new_feature;
if(segment_feature.getEmblFeature() instanceof GFFStreamFeature)
{
final FeatureVector chadoGenes = new FeatureVector();
chadoGenes.add(segment_feature);
final Vector duplicateGenes = duplicateGeneFeatures(frame, chadoGenes, entry_group);
// get the new duplicate spliced feature
ChadoCanonicalGene chado_gene = (ChadoCanonicalGene)duplicateGenes.get(0);
// assumes single transcript
uk.ac.sanger.artemis.io.Feature transcript =
(uk.ac.sanger.artemis.io.Feature)chado_gene.getTranscripts().get(0);
// get the spliced feature with the same key as the segment
// selected to unmerge
uk.ac.sanger.artemis.io.Feature spliced = (uk.ac.sanger.artemis.io.Feature)
chado_gene.getSpliceSitesOfTranscript(GeneUtils.getUniqueName(transcript),
first_segment.getFeature().getKey().getKeyString()).get(0);
new_feature = (Feature)spliced.getUserData();
}
else
new_feature = segment_feature.duplicate(true);
// we set the Selection later
selection.clear ();
// delete the segments starting at index_of_second_segment from
// segment_feature and delete the segments up to (and including)
// index_of_first_segment from new_feature
for(int i = all_feature_segments.size() - 1;
i >= index_of_second_segment; --i)
{
segment_feature.getSegments ().elementAt (i).removeFromFeature ();
}
// remove the first segment of new_feature index_of_first_segment times
if(segment_feature.getEmblFeature() instanceof GFFStreamFeature)
{
GeneUtils.checkGeneBoundary(
((GFFStreamFeature)segment_feature.getEmblFeature()).getChadoGene());
GeneUtils.checkGeneBoundary(
((GFFStreamFeature)new_feature.getEmblFeature()).getChadoGene());
}
selection.set (segment_feature.getSegments ().lastElement ());
selection.add (new_feature.getSegments ().elementAt (0));
final String message =
"the selected exons (in " +
segment_feature.getIDString () +
") are in a read only entry - cannot continue";
new MessageDialog (frame, message);
throw new Error ("internal error - unexpected exception: " + e);
}
entry_group.getActionController ().endAction ();
}
}
/**
* If the selection contains exactly one feature this routine will
* remove all the joins.
* @param frame The JFrame to use for MessageDialog components.
* @param selection The Selection containing the segments to unmerge.
* @param entry_group Used to get the ActionController for calling
* startAction() and endAction().
**/
private static void unmergeAllFeature(final JFrame frame,
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
final Selection selection,
final EntryGroup entry_group)
{
try
{
entry_group.getActionController ().startAction ();
final FeatureVector delete_features = selection.getAllFeatures();
if(delete_features.size() > 1)
{
new MessageDialog (frame, "Select just one feature");
return;
}
final FeatureSegmentVector selected_segments =
delete_features.elementAt(0).getSegments();
try
{
Vector new_features = new Vector();
Vector segment_to_remove = new Vector();
FeatureSegment[] selected_segments_array = new FeatureSegment[selected_segments.size()];
for(int i=0; i<selected_segments.size(); i++)
{
FeatureSegment seg = selected_segments.elementAt(i);
int index_of_segment = selected_segments.indexOf(seg);
selected_segments_array[index_of_segment] = seg;
}
for(int i=0; i<selected_segments.size()-1; i++)
{
final Feature new_feature = segment_feature.duplicate();
segment_to_remove.add(segment);
FeatureSegmentVector new_segments = new_feature.getSegments();
Vector removals = new Vector();
for(int j = 0 ; j <new_segments.size(); j++)
{
if(i != j)
}
for(int j = 0; j < removals.size(); j++)
new_feature.removeSegment( (FeatureSegment)removals.get(j) );
new_features.add(new_feature);
}
final int size = segment_to_remove.size();
for(int i=0; i<size; i++)
selected_segments_array[size-1].getFeature().removeSegment(
(FeatureSegment)segment_to_remove.get(i) );
{
feature = (Feature)new_features.get(i);
selection.add(feature.getSegments().elementAt(0));
// set GFF ID's
if(feature.getEmblFeature() instanceof GFFStreamFeature)
setGffId(selected_segments_array[0].getFeature(), feature);
}
// set GFF ID's
feature = selected_segments_array[size-1].getFeature();
if(feature.getEmblFeature() instanceof GFFStreamFeature)
setGffId(selected_segments_array[0].getFeature(), feature);
}
catch(ReadOnlyException e)
{
final String message =
"the selected exons (in " +
delete_features.elementAt(0).getIDString () +
") are in a read only entry - cannot continue";
new MessageDialog (frame, message);
}
catch (LastSegmentException e)
{
throw new Error ("internal error - unexpected exception: " + e);
}
}
finally
{
entry_group.getActionController ().endAction ();
}
}
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
/**
* Sets the ID based on the new features ranges.
* @param feature_original
* @param feature_new
*/
private static void setGffId(final Feature feature_original,
final Feature feature_new)
{
RangeVector ranges = feature_new.getLocation().getRanges();
GFFStreamFeature gff_feature =
(GFFStreamFeature)feature_original.getEmblFeature();
String id1 = gff_feature.getSegmentID(ranges);
try
{
feature_new.getEmblFeature().setQualifier(new Qualifier("ID", id1));
}
catch(ReadOnlyException e)
{
e.printStackTrace();
}
catch(EntryInformationException e)
{
e.printStackTrace();
}
}
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
/**
* Create a QualifierEditor JFrame that acts on the selected features.
* @param frame The JFrame to use for MessageDialog components.
**/
private void addQualifiers (final JFrame frame, final Selection selection) {
if (!checkForSelectionFeatures (frame, selection)) {
return;
}
final FeatureVector selected_features = selection.getAllFeatures ();
if (getReadOnlyFeatures (selected_features).size () > 0) {
new MessageDialog (frame,
"one or more of the selected features is read-only " +
"- cannot continue");
return;
}
final QualifierEditor qualifier_editor =
new QualifierEditor (selected_features, getEntryGroup ());
qualifier_editor.setVisible (true);
}
/**
* Offer the user a choice of qualifier to remove from the selected features
**/
private void removeQualifier (final JFrame frame, final Selection selection) {
if (!checkForSelectionFeatures (frame, selection)) {
return;
}
final FeatureVector selected_features = selection.getAllFeatures ();
final StringVector qualifier_names =
Feature.getAllQualifierNames (selected_features);
if (qualifier_names.size () == 0) {
new MessageDialog (getParentFrame (), "feature has no qualifiers");
return;
}
final ChoiceFrame choice_frame =
new ChoiceFrame ("Select a qualifer name", qualifier_names);
final JComboBox choice = choice_frame.getChoice ();
final int MAX_VISIBLE_ROWS = 30;
choice.setMaximumRowCount (MAX_VISIBLE_ROWS);
choice.addItemListener (new ItemListener () {
public void itemStateChanged (ItemEvent _) {
removeQualifierFromFeatures (selected_features,
(String) choice.getSelectedItem ());
choice_frame.setVisible (false);
choice_frame.dispose ();
}
});
choice_frame.getOKButton ().addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent _) {
removeQualifierFromFeatures (selected_features,
(String) choice.getSelectedItem ());
}
});
choice_frame.setVisible (true);
}
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
private void convertKeys(final JFrame frame,
final Selection selection)
{
if (!checkForSelectionFeatures (frame, selection))
return;
final FeatureVector selected_features = selection.getAllFeatures ();
Entry default_entry = getEntryGroup().getDefaultEntry();
if(default_entry == null)
default_entry = getEntryGroup().elementAt(0);
final EntryInformation default_entry_information =
default_entry.getEntryInformation();
final KeyChoice key_selector = new KeyChoice(default_entry_information);
final String options[] = { "Convert", "Cancel" };
final int opt = JOptionPane.showOptionDialog(frame,
key_selector, "Convert Key(s) of Selected Features",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if(opt == 1)
return;
entry_group.getActionController ().startAction ();
try
{
for(int i=0; i<selected_features.size(); i++)
{
Feature feature = selected_features.elementAt(i);
feature.set(key_selector.getSelectedItem(),
feature.getLocation(), feature.getQualifiers());
}
}
catch(ReadOnlyException e)
{
JOptionPane.showMessageDialog(frame,
"Cannot convert read-only features.",
"Error Converting Key(s)", JOptionPane.ERROR_MESSAGE);
}
catch(EntryInformationException e)
{
JOptionPane.showMessageDialog(frame,
e.getMessage(),
"Error Converting Key(s)", JOptionPane.ERROR_MESSAGE);
}
catch(OutOfRangeException e)
{
JOptionPane.showMessageDialog(frame,
e.getMessage(),
"Error Converting Key(s)", JOptionPane.ERROR_MESSAGE);
}
finally
{
entry_group.getActionController ().endAction();
}
}
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
/**
* Offer the user a choice of qualifier to convert the name of
* from the selected features
* @param frame
* @param selection
*/
private void convertQualifier (final JFrame frame,
final Selection selection)
{
if (!checkForSelectionFeatures (frame, selection))
return;
final FeatureVector selected_features = selection.getAllFeatures ();
final StringVector qualifier_names =
Feature.getAllQualifierNames (selected_features);
if(qualifier_names.size () == 0)
{
new MessageDialog (getParentFrame (), "feature has no qualifiers");
return;
}
Box yBox = Box.createVerticalBox();
final JComboBox convertFrom = new JComboBox(qualifier_names);
final QualifierChoice convertTo = new QualifierChoice(
getEntryGroup().getDefaultEntry().getEntryInformation(),
selected_features.elementAt(0).getKey(),null,
false);
Box xBox = Box.createHorizontalBox();
xBox.add(new JLabel("Convert all qualifiers of type:"));
xBox.add(Box.createHorizontalGlue());
yBox.add(xBox);
yBox.add(convertFrom);
xBox = Box.createHorizontalBox();
xBox.add(new JLabel("To:"));
xBox.add(Box.createHorizontalGlue());
yBox.add(xBox);
yBox.add(convertTo);
int select = JOptionPane.showConfirmDialog(frame, yBox,
"Convert Qualifiers",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
String oldQualifierName = (String)convertFrom.getSelectedItem();
String newQualifierName = (String)convertTo.getSelectedItem();
if(select == JOptionPane.CANCEL_OPTION ||
oldQualifierName.equals(newQualifierName))
return;
try
{
for(int i=0; i<selected_features.size(); i++)
{
Feature feature = selected_features.elementAt(i);
QualifierVector qualifiers = feature.getQualifiers();
int index = qualifiers.indexOfQualifierWithName(oldQualifierName);
if(index == -1)
continue;