/plugins/SVNPlugin/trunk/src/ise/plugin/svn/action/LockAction.java

# · Java · 160 lines · 103 code · 18 blank · 39 comment · 15 complexity · 48fae247cdbb83fb06bdf436c5b5a625 MD5 · raw file

  1. /*
  2. Copyright (c) 2007, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the author nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package ise.plugin.svn.action;
  26. import ise.plugin.svn.gui.OutputPanel;
  27. import ise.plugin.svn.SVNPlugin;
  28. import ise.plugin.svn.command.Lock;
  29. import ise.plugin.svn.data.CommitData;
  30. import ise.plugin.svn.data.LockResults;
  31. import ise.plugin.svn.gui.LockDialog;
  32. import ise.plugin.svn.gui.AddResultsPanel;
  33. import ise.plugin.svn.io.ConsolePrintStream;
  34. import ise.plugin.svn.library.GUIUtils;
  35. import common.swingworker.*;
  36. import java.awt.event.ActionEvent;
  37. import java.io.*;
  38. import java.util.*;
  39. import java.util.logging.*;
  40. import javax.swing.JPanel;
  41. import org.gjt.sp.jedit.View;
  42. import org.gjt.sp.jedit.jEdit;
  43. /**
  44. * ActionListener to perform an svn lock.
  45. * This is not dependent on ProjectViewer.
  46. */
  47. public class LockAction extends SVNAction {
  48. private LockDialog dialog = null;
  49. private List<String> paths = null;
  50. private boolean remote = false;
  51. /**
  52. * @param view the View in which to display results
  53. * @param paths a list of paths to be added
  54. * @param username the username for the svn repository
  55. * @param password the password for the username
  56. * @param remote true if attempting to lock a remote repository file
  57. */
  58. public LockAction( View view, List<String> paths, String username, String password, boolean remote ) {
  59. super( view, jEdit.getProperty( "ips.Lock", "Lock" ) );
  60. if ( paths == null )
  61. throw new IllegalArgumentException( "paths may not be null" );
  62. this.paths = paths;
  63. setUsername( username );
  64. setPassword( password );
  65. this.remote = remote;
  66. }
  67. public void actionPerformed( ActionEvent ae ) {
  68. if ( paths != null && paths.size() > 0 ) {
  69. dialog = new LockDialog( getView(), paths, true, remote );
  70. GUIUtils.center( getView(), dialog );
  71. dialog.setVisible( true );
  72. final CommitData data = dialog.getData();
  73. if ( data == null ) {
  74. return ; // null means user canceled
  75. }
  76. if ( getUsername() == null ) {
  77. verifyLogin( data.getPaths() == null ? null : data.getPaths().get( 0 ) );
  78. if ( isCanceled() ) {
  79. return ;
  80. }
  81. }
  82. data.setUsername( getUsername() );
  83. data.setPassword( getPassword() );
  84. data.setOut( new ConsolePrintStream( getView() ) );
  85. getView().getDockableWindowManager().showDockableWindow( "subversion" );
  86. final OutputPanel panel = SVNPlugin.getOutputPanel( getView() );
  87. panel.showConsole();
  88. final Logger logger = panel.getLogger();
  89. logger.log( Level.INFO, jEdit.getProperty( "ips.Locking_...", "Locking ..." ) );
  90. for ( Handler handler : logger.getHandlers() ) {
  91. handler.flush();
  92. }
  93. class Runner extends SwingWorker<LockResults, Object> {
  94. @Override
  95. public LockResults doInBackground() {
  96. try {
  97. Lock lock = new Lock();
  98. return lock.lock( data );
  99. }
  100. catch ( Exception e ) {
  101. data.getOut().printError( e.getMessage() );
  102. }
  103. finally {
  104. data.getOut().close();
  105. }
  106. return null;
  107. }
  108. @Override
  109. public boolean cancel( boolean mayInterruptIfRunning ) {
  110. boolean cancelled = super.cancel( mayInterruptIfRunning );
  111. if ( cancelled ) {
  112. data.getOut().printError( "Stopped 'Lock' action." );
  113. data.getOut().close();
  114. }
  115. else {
  116. data.getOut().printError( "Unable to stop 'Lock' action." );
  117. }
  118. return cancelled;
  119. }
  120. @Override
  121. protected void done() {
  122. if ( isCancelled() ) {
  123. return ;
  124. }
  125. try {
  126. JPanel results_panel = new AddResultsPanel( get(), AddResultsPanel.LOCK, getView(), getUsername(), getPassword() );
  127. panel.addTab( jEdit.getProperty( "ips.Locked", "Locked" ), results_panel );
  128. }
  129. catch ( Exception e ) { // NOPMD
  130. // ignored
  131. }
  132. }
  133. }
  134. Runner runner = new Runner();
  135. panel.addWorker( "Lock", runner );
  136. runner.execute();
  137. }
  138. }
  139. }