4242
4343public class ContributionListPanel extends JPanel implements Scrollable , ContributionChangeListener {
4444
45- static public final String DELETION_MESSAGE = "<html><body>< i>This tool has "
45+ static public final String DELETION_MESSAGE = "<i>This tool has "
4646 + "been flagged for deletion. Restart all instances of the editor to "
47- + "finalize the removal process.</i></body></html> " ;
47+ + "finalize the removal process.</i>" ;
4848
4949 static public final String INSTALL_FAILURE_TITLE = "Install Failed" ;
5050
@@ -354,7 +354,7 @@ private class ContributionPanel extends JPanel {
354354
355355 /** Should only be set through setContribution(), otherwise UI components
356356 * will not be updated. */
357- Contribution info ;
357+ Contribution contrib ;
358358
359359 boolean alreadySelected ;
360360
@@ -386,6 +386,8 @@ private class ContributionPanel extends JPanel {
386386
387387 private ActionListener installActionListener ;
388388
389+ private ActionListener undoActionListener ;
390+
389391 private ContributionPanel () {
390392
391393 htmlPanes = new HashSet <JTextPane >();
@@ -406,35 +408,37 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
406408 };
407409
408410 installActionListener = new ActionListener () {
409- public void actionPerformed (ActionEvent arg ) {
410- if (info instanceof AdvertisedContribution ) {
411- installContribution ((AdvertisedContribution ) info );
411+ public void actionPerformed (ActionEvent e ) {
412+ if (contrib instanceof AdvertisedContribution ) {
413+ installContribution ((AdvertisedContribution ) contrib );
414+ }
415+ }
416+ };
417+
418+ undoActionListener = new ActionListener () {
419+ public void actionPerformed (ActionEvent e ) {
420+ if (contrib instanceof InstalledContribution ) {
421+ InstalledContribution installed = (InstalledContribution ) contrib ;
422+ ContributionManager .removeFlagForDeletion (installed );
423+ contribManager .getListing ().replaceContribution (contrib , contrib );
412424 }
413425 }
414426 };
415427
416428 removeActionListener = new ActionListener () {
417429 public void actionPerformed (ActionEvent arg ) {
418- if (info .isInstalled () && info instanceof InstalledContribution ) {
430+ if (contrib .isInstalled () && contrib instanceof InstalledContribution ) {
419431 updateButton .setEnabled (false );
420432 installOrRemoveButton .setEnabled (false );
421433
422434 installProgressBar .setVisible (true );
423- contribManager .removeContribution ((InstalledContribution ) info ,
435+ contribManager .removeContribution ((InstalledContribution ) contrib ,
424436 new JProgressMonitor (installProgressBar ) {
425437
426438 public void finishedAction () {
427439 // Finished uninstalling the library
428440 resetInstallProgressBarState ();
429-
430- switch (info .getType ()) {
431- case LIBRARY :
432- case LIBRARY_COMPILATION :
433- installOrRemoveButton .setEnabled (true );
434- break ;
435- case TOOL :
436- descriptionText .setText (DELETION_MESSAGE );
437- }
441+ installOrRemoveButton .setEnabled (true );
438442 }
439443 });
440444 }
@@ -515,7 +519,7 @@ private void addPaneComponents() {
515519
516520 iconArea = new JPanel () {
517521 protected void paintComponent (Graphics g ) {
518- Image icon = contribManager .getContributionIcon (info .getType ());
522+ Image icon = contribManager .getContributionIcon (contrib .getType ());
519523 if (icon != null ) {
520524 g .drawImage (icon , 0 , 0 , this );
521525 }
@@ -580,7 +584,7 @@ protected void paintComponent(Graphics g) {
580584 public void actionPerformed (ActionEvent e ) {
581585 updateButton .setEnabled (false );
582586 // XXX: There is a bug here. The advertised library will be 'replaced' instead
583- installContribution ((AdvertisedContribution ) contribManager .contribListing .getAdvertisedContribution (info ));
587+ installContribution ((AdvertisedContribution ) contribManager .contribListing .getAdvertisedContribution (contrib ));
584588 }
585589 });
586590 descriptionPanel .add (updateButton , c );
@@ -648,36 +652,46 @@ private void setExpandListener(Component component,
648652 }
649653 }
650654
651- public void setContribution (Contribution info ) {
655+ public void setContribution (Contribution contrib ) {
652656
653- this .info = info ;
657+ this .contrib = contrib ;
654658
655659 setFocusable (true );
656660
657661 StringBuilder nameText = new StringBuilder ();
658662 nameText .append ("<html><body><b>" );
659- if (info .getUrl () == null ) {
660- nameText .append (info .getName ());
663+ if (contrib .getUrl () == null ) {
664+ nameText .append (contrib .getName ());
661665 } else {
662- nameText .append ("<a href=\" " + info .getUrl () + "\" >" + info .getName () + "</a>" );
666+ nameText .append ("<a href=\" " + contrib .getUrl () + "\" >" + contrib .getName () + "</a>" );
663667 }
664668 nameText .append ("</b>" );
665- nameText .append (createAuthorString (info .getAuthorList ()));
669+ nameText .append (createAuthorString (contrib .getAuthorList ()));
666670 nameText .append ("</body></html>" );
667671 headerText .setText (nameText .toString ());
668672
669- categoryLabel .setText ("[" + info .getCategory () + "]" );
673+ categoryLabel .setText ("[" + contrib .getCategory () + "]" );
670674
671675 StringBuilder description = new StringBuilder ();
672676 description .append ("<html><body>" );
673- if (info .getSentence () != null )
674- description .append (info .getSentence ());
677+
678+ if (ContributionManager .isFlaggedForDeletion (contrib )) {
679+ description .append (DELETION_MESSAGE );
680+ installOrRemoveButton .setText ("Undo" );
681+ installOrRemoveButton .addActionListener (new ActionListener () {
682+ public void actionPerformed (ActionEvent e ) {
683+
684+ }
685+ });
686+ } else if (contrib .getSentence () != null ) {
687+ description .append (contrib .getSentence ());
688+ }
675689
676690 description .append ("</body></html>" );
677691 descriptionText .setText (description .toString ());
678692 setAlignment (descriptionText , StyleConstants .ALIGN_JUSTIFIED );
679693
680- if (contribManager .getListing ().hasUpdates (info )) {
694+ if (contribManager .getListing ().hasUpdates (contrib )) {
681695 StringBuilder versionText = new StringBuilder ();
682696 versionText .append ("<html><body><i>" );
683697 versionText .append ("New version available!" );
@@ -690,12 +704,21 @@ public void setContribution(Contribution info) {
690704 updateButton .setVisible (false );
691705 }
692706
693- if (info .isInstalled ()) {
694- installOrRemoveButton .removeActionListener (installActionListener );
695- installOrRemoveButton .addActionListener (removeActionListener );
696- installOrRemoveButton .setText ("Remove" );
707+ if (contrib .isInstalled ()) {
708+ if (ContributionManager .isFlaggedForDeletion (contrib )) {
709+ installOrRemoveButton .removeActionListener (installActionListener );
710+ installOrRemoveButton .removeActionListener (removeActionListener );
711+ installOrRemoveButton .addActionListener (undoActionListener );
712+ installOrRemoveButton .setText ("Undo" );
713+ } else {
714+ installOrRemoveButton .removeActionListener (installActionListener );
715+ installOrRemoveButton .removeActionListener (undoActionListener );
716+ installOrRemoveButton .addActionListener (removeActionListener );
717+ installOrRemoveButton .setText ("Remove" );
718+ }
697719 } else {
698720 installOrRemoveButton .removeActionListener (removeActionListener );
721+ installOrRemoveButton .removeActionListener (undoActionListener );
699722 installOrRemoveButton .addActionListener (installActionListener );
700723 installOrRemoveButton .setText ("Install" );
701724 }
@@ -816,7 +839,7 @@ public void setSelected(boolean isSelected) {
816839 enableHyperlinks = alreadySelected ;
817840
818841 updateButton .setVisible (isSelected ()
819- && contribManager .getListing ().hasUpdates (info ));
842+ && contribManager .getListing ().hasUpdates (contrib ));
820843 installOrRemoveButton .setVisible (isSelected ());
821844
822845 for (JTextPane textPane : htmlPanes ) {
0 commit comments