Skip to content

Commit 7bfa4ab

Browse files
committed
Fix notification link for updating #47
1 parent 1d8383b commit 7bfa4ab

4 files changed

Lines changed: 99 additions & 10 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2015 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.update;
43+
44+
import org.openide.DialogDisplayer;
45+
import org.openide.NotifyDescriptor;
46+
import org.openide.util.NbBundle;
47+
48+
/**
49+
*
50+
* @author junichi11
51+
*/
52+
public final class UpgradeUtils {
53+
54+
private UpgradeUtils() {
55+
}
56+
57+
@NbBundle.Messages("UpgradeUtils.invalid.wpcli.message=Not found wp-cli: You can update the WordPress using the update command of wp-cli from this link if wp-cli path and locale are set to the Options.")
58+
public static void showInvalidWpCliDialog() {
59+
NotifyDescriptor.Message message = new NotifyDescriptor.Message(
60+
Bundle.UpgradeUtils_invalid_wpcli_message(),
61+
NotifyDescriptor.INFORMATION_MESSAGE
62+
);
63+
DialogDisplayer.getDefault().notify(message);
64+
}
65+
}

src/org/netbeans/modules/php/wordpress/update/WordPressCoreUpgradeChecker.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.awt.event.ActionListener;
4646
import java.io.IOException;
4747
import java.net.MalformedURLException;
48+
import java.net.URL;
4849
import java.util.Collections;
4950
import java.util.concurrent.ExecutionException;
5051
import java.util.concurrent.Future;
@@ -60,6 +61,7 @@
6061
import org.netbeans.modules.php.wordpress.wpapis.WordPressVersionCheckApi;
6162
import org.openide.DialogDisplayer;
6263
import org.openide.NotifyDescriptor;
64+
import org.openide.awt.HtmlBrowser;
6365
import org.openide.awt.NotificationDisplayer;
6466
import org.openide.util.Exceptions;
6567
import org.openide.util.ImageUtilities;
@@ -74,6 +76,7 @@
7476
public final class WordPressCoreUpgradeChecker implements WordPressUpgradeChecker {
7577

7678
private String upgradeVersionNumber;
79+
private String downloadUrl;
7780
private static final Logger LOGGER = Logger.getLogger(WordPressCoreUpgradeChecker.class.getName());
7881

7982
public WordPressCoreUpgradeChecker() {
@@ -90,6 +93,7 @@ public boolean hasUpgrade(PhpModule phpModule) {
9093
WordPressVersionCheckApi versionCheckApi = new WordPressVersionCheckApi();
9194
versionCheckApi.parse();
9295
upgradeVersionNumber = versionCheckApi.getVersion();
96+
downloadUrl = versionCheckApi.getDownload();
9397
if (StringUtils.isEmpty(upgradeVersionNumber)) {
9498
// XXX throw exception?
9599
return false;
@@ -149,17 +153,18 @@ private boolean hasUpgrade(WordPressVersion version) throws NumberFormatExceptio
149153
"WordPressCoreUpgradeChecker.core.notify.title=Notification({0}): New version is available",
150154
"# {0} - version number",
151155
"# {1} - display name",
152-
"WordPressCoreUpgradeChecker.core.notify.detail=New core version is available: {0} ({1})",})
156+
"WordPressCoreUpgradeChecker.core.notify.detail=New core version is available: {0} ({1})"
157+
})
153158
@Override
154159
public void notifyUpgrade(PhpModule phpModule) {
155-
if (StringUtils.isEmpty(upgradeVersionNumber)) {
160+
if (StringUtils.isEmpty(upgradeVersionNumber) || StringUtils.isEmpty(downloadUrl)) {
156161
return;
157162
}
158163
NotificationDisplayer.getDefault().notify(
159164
Bundle.WordPressCoreUpgradeChecker_core_notify_title(phpModule.getDisplayName()),
160165
ImageUtilities.loadImageIcon(WordPress.WP_ICON_16, false),
161166
Bundle.WordPressCoreUpgradeChecker_core_notify_detail(upgradeVersionNumber, phpModule.getDisplayName()),
162-
new CoreUpdateActionListener(phpModule)
167+
new CoreUpdateActionListener(phpModule, downloadUrl)
163168
);
164169
}
165170

@@ -171,15 +176,36 @@ public String getUpgradeVersionNumber() {
171176
private static class CoreUpdateActionListener implements ActionListener {
172177

173178
private final PhpModule phpModule;
179+
private final String downloadUrl;
174180

175-
public CoreUpdateActionListener(PhpModule phpModule) {
181+
public CoreUpdateActionListener(PhpModule phpModule, String downloadUrl) {
176182
this.phpModule = phpModule;
183+
this.downloadUrl = downloadUrl;
177184
}
178185

179-
@NbBundle.Messages("CoreUpdateActionListener.comfirmation=Do you want to update? (run wp core update, update-db)")
186+
@NbBundle.Messages({
187+
"CoreUpdateActionListener.comfirmation=Do you want to update? (run wp core update, update-db)",
188+
"# {0} - download url",
189+
"CoreUpdateActionListener.download.zip.confirmation=<html><p>Dou you want to download the zip file({0}) on the browsser?</p>"
190+
+ "<b>NOTE:</b> You can also update the WP using the update command of wp-cli if you set wp-cli to the Options"
191+
})
180192
@Override
181193
public void actionPerformed(ActionEvent e) {
182194
if (StringUtils.isEmpty(WordPressOptions.getInstance().getWpCliPath())) {
195+
// show dialog
196+
NotifyDescriptor.Confirmation message = new NotifyDescriptor.Confirmation(
197+
Bundle.CoreUpdateActionListener_download_zip_confirmation(downloadUrl),
198+
NotifyDescriptor.QUESTION_MESSAGE
199+
);
200+
if (DialogDisplayer.getDefault().notify(message) == NotifyDescriptor.OK_OPTION) {
201+
if (!StringUtils.isEmpty(downloadUrl)) {
202+
try {
203+
HtmlBrowser.URLDisplayer.getDefault().showURL(new URL(downloadUrl));
204+
} catch (MalformedURLException ex) {
205+
Exceptions.printStackTrace(ex);
206+
}
207+
}
208+
}
183209
return;
184210
}
185211

@@ -207,11 +233,7 @@ public void run() {
207233
if (result != null) {
208234
result.get();
209235
}
210-
} catch (InvalidPhpExecutableException ex) {
211-
Exceptions.printStackTrace(ex);
212-
} catch (InterruptedException ex) {
213-
Exceptions.printStackTrace(ex);
214-
} catch (ExecutionException ex) {
236+
} catch (InvalidPhpExecutableException | InterruptedException | ExecutionException ex) {
215237
Exceptions.printStackTrace(ex);
216238
}
217239
}

src/org/netbeans/modules/php/wordpress/update/WordPressPluginUpgradeChecker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public PluginUpdateActionListener(PhpModule phpModule) {
150150
@Override
151151
public void actionPerformed(ActionEvent e) {
152152
if (StringUtils.isEmpty(WordPressOptions.getInstance().getWpCliPath())) {
153+
UpgradeUtils.showInvalidWpCliDialog();
153154
return;
154155
}
155156

src/org/netbeans/modules/php/wordpress/update/WordPressThemeUpgradeChecker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public ThemeUpdateActionListener(PhpModule phpModule) {
150150
@Override
151151
public void actionPerformed(ActionEvent e) {
152152
if (StringUtils.isEmpty(WordPressOptions.getInstance().getWpCliPath())) {
153+
UpgradeUtils.showInvalidWpCliDialog();
153154
return;
154155
}
155156

0 commit comments

Comments
 (0)