4444import java .awt .event .ActionEvent ;
4545import java .awt .event .ActionListener ;
4646import java .io .IOException ;
47+ import java .util .logging .Level ;
48+ import java .util .logging .Logger ;
4749import org .netbeans .modules .php .wordpress .WordPress ;
4850import org .netbeans .modules .php .wordpress .util .WPFileUtils ;
51+ import org .openide .DialogDisplayer ;
52+ import org .openide .NotifyDescriptor ;
4953import org .openide .awt .ActionID ;
5054import org .openide .awt .ActionReference ;
5155import org .openide .awt .ActionReferences ;
5256import org .openide .awt .ActionRegistration ;
5357import org .openide .filesystems .FileObject ;
5458import org .openide .loaders .DataObject ;
55- import org .openide .util .Exceptions ;
5659import org .openide .util .NbBundle .Messages ;
5760
5861@ ActionID (
6972public final class ZipAction implements ActionListener {
7073
7174 private final DataObject context ;
75+ private static final Logger LOGGER = Logger .getLogger (ZipAction .class .getName ());
7276
7377 public ZipAction (DataObject context ) {
7478 this .context = context ;
7579 }
7680
81+ @ Messages ({
82+ "# {0} - file name" ,
83+ "ZipAction.error.file.already.exist=Zip file ({0}) already exists."
84+ })
7785 @ Override
7886 public void actionPerformed (ActionEvent ev ) {
7987 if (!isValidDirectory ()) {
@@ -85,7 +93,9 @@ public void actionPerformed(ActionEvent ev) {
8593 try {
8694 WPFileUtils .zip (target );
8795 } catch (IOException ex ) {
88- Exceptions .printStackTrace (ex );
96+ // #36
97+ LOGGER .log (Level .WARNING , ex .getMessage ());
98+ showErrorDialog (Bundle .ZipAction_error_file_already_exist (target .getName () + ".zip" )); // NOI18N
8999 }
90100 }
91101
@@ -110,9 +120,26 @@ private boolean isValidDirectory() {
110120 String name = parent .getNameExt ();
111121 if (parent .isFolder ()) {
112122 if (name .equals ("plugins" ) || name .equals ("themes" )) { // NOI18N
123+ // #36
124+ String zipFileName = target .getName () + ".zip" ; // NOI18N
125+ FileObject zipFile = parent .getFileObject (zipFileName );
126+ if (zipFile != null ) {
127+ showErrorDialog (Bundle .ZipAction_error_file_already_exist (zipFileName ));
128+ return false ;
129+ }
113130 return true ;
114131 }
115132 }
116133 return false ;
117134 }
135+
136+ /**
137+ * Show error message dialog.
138+ *
139+ * @param errorMessage Error message
140+ */
141+ private void showErrorDialog (String errorMessage ) {
142+ NotifyDescriptor .Message message = new NotifyDescriptor .Message (errorMessage , NotifyDescriptor .ERROR_MESSAGE );
143+ DialogDisplayer .getDefault ().notify (message );
144+ }
118145}
0 commit comments