use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.
the class InstallStep method notifyWritePermissionProblem.
@Messages({ "# {0} - plugin_name", "inBackground_WritePermission=You don''t have permission to install plugin {0} into the installation directory.", "inBackground_WritePermission_Details=details", "cancel=Cancel", "install=Install anyway" })
private void notifyWritePermissionProblem(final OperationException ex, final UpdateElement culprit) {
// lack of privileges for writing
ActionListener onMouseClickAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProblemPanel problem = new ProblemPanel(ex, culprit, false);
problem.showWriteProblemDialog();
}
};
String title = inBackground_WritePermission(culprit.getDisplayName());
String description = inBackground_WritePermission_Details();
NotificationDisplayer.getDefault().notify(title, // NOI18N
ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/error.png", false), description, onMouseClickAction, NotificationDisplayer.Priority.HIGH, NotificationDisplayer.Category.ERROR);
}
use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.
the class InstallStep method notifyNetworkProblem.
private void notifyNetworkProblem(final OperationException ex) {
// Some network problem found
ActionListener onMouseClickAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProblemPanel problem = new ProblemPanel(ex, false);
problem.showNetworkProblemDialog();
}
};
String title = getBundle("InstallSupport_InBackground_NetworkError");
String description = getBundle("InstallSupport_InBackground_NetworkError_Details");
NotificationDisplayer.getDefault().notify(title, ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/error.png", false), description, onMouseClickAction, NotificationDisplayer.Priority.HIGH, NotificationDisplayer.Category.ERROR);
}
use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.
the class InstallStep method handleValidation.
private Installer handleValidation(Validator v, final InstallSupport support) {
if (canceled) {
log.fine("Quit handleValidation() because an previous installation was canceled.");
return null;
}
component.setHeadAndContent(getBundle(HEAD_VERIFY), getBundle(CONTENT_VERIFY));
ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
if (runInBackground()) {
systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
handleCancel();
return true;
}
});
handle = systemHandle;
} else {
spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
handleCancel();
return true;
}
});
totalUnits = model.getInstallContainer().listAll().size();
processedUnits = 0;
if (indeterminateProgress) {
detailLabel.addPropertyChangeListener(TEXT_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
assert TEXT_PROPERTY.equals(evt.getPropertyName()) : "Listens onlo on " + TEXT_PROPERTY + " but was " + evt;
if (evt.getOldValue() != evt.getNewValue()) {
processedUnits++;
if (indeterminateProgress && spareHandleStarted) {
if (processedUnits < totalUnits - 1) {
totalUnits = totalUnits - processedUnits;
spareHandle.switchToDeterminate(totalUnits);
indeterminateProgress = false;
}
}
if (!indeterminateProgress) {
spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
}
}
}
});
}
}
handle.setInitialDelay(0);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
if (spareHandle != null && spareHandleStarted) {
spareHandle.finish();
}
Installer tmpInst;
try {
tmpInst = support.doValidate(v, handle);
if (tmpInst == null)
return null;
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
ProblemPanel problem = new ProblemPanel(ex, detailLabel.getText(), false);
if (ex.getErrorType() == OperationException.ERROR_TYPE.MODIFIED) {
problem.showModifiedProblemDialog(detailLabel.getText());
} else {
problem.showNetworkProblemDialog();
}
handleCancel();
return null;
}
final Installer inst = tmpInst;
List<UpdateElement> signedVerified = new ArrayList<UpdateElement>();
List<UpdateElement> signedUnverified = new ArrayList<UpdateElement>();
List<UpdateElement> unsigned = new ArrayList<UpdateElement>();
List<UpdateElement> modified = new ArrayList<UpdateElement>();
int trustedCount = 0;
Map<Object, String> certs = new HashMap<>();
for (UpdateElement el : model.getAllUpdateElements()) {
boolean writeCert = false;
if (support.isContentModified(inst, el)) {
modified.add(el);
continue;
} else if (support.isTrusted(inst, el)) {
trustedCount++;
continue;
} else if (support.isSignedVerified(inst, el)) {
signedVerified.add(el);
writeCert = true;
} else if (support.isSignedUnverified(inst, el)) {
signedUnverified.add(el);
writeCert = true;
} else {
unsigned.add(el);
}
if (writeCert) {
String cert = support.getCertificate(inst, el);
if (cert != null && cert.length() > 0) {
certs.put(el.getDisplayName(), cert);
}
}
}
if (signedVerified.size() > 0 || signedUnverified.size() > 0 || unsigned.size() > 0 || modified.size() > 0 && !runInBackground()) {
int total = trustedCount + signedVerified.size() + signedUnverified.size() + unsigned.size();
final ValidationWarningPanel p = new ValidationWarningPanel(signedVerified, signedUnverified, unsigned, modified, total);
final boolean verifyCertificate = (!signedVerified.isEmpty() || !signedUnverified.isEmpty()) && !certs.isEmpty();
JButton[] options;
JButton[] closeOptions;
final JButton cancel = model.getCancelButton(wd);
DialogDescriptor dd = new DialogDescriptor(p, verifyCertificate ? getBundle("ValidationWarningPanel_VerifyCertificate_Title") : getBundle("ValidationWarningPanel_Title"));
JButton canContinue = new JButton();
canContinue.setDefaultCapable(false);
if (modified.isEmpty()) {
final JButton showDetails = new JButton();
Mnemonics.setLocalizedText(showDetails, getBundle("ValidationWarningPanel_ShowDetailsButton"));
final Map<Object, String> certsMap = certs;
showDetails.setEnabled(false);
p.addSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getNewLeadSelectionPath().getPathCount() == 3 && certsMap.containsKey(p.getSelectedNode())) {
showDetails.setEnabled(true);
} else {
showDetails.setEnabled(false);
}
}
});
showDetails.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (showDetails.equals(e.getSource())) {
Object node = p.getSelectedNode();
if (certsMap.containsKey(node)) {
JTextArea ta = new JTextArea(certsMap.get(node));
ta.setEditable(false);
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ta));
}
}
}
});
Mnemonics.setLocalizedText(canContinue, getBundle("ValidationWarningPanel_ContinueButton"));
if (verifyCertificate) {
dd.setAdditionalOptions(new JButton[] { showDetails });
}
options = new JButton[] { canContinue, cancel };
closeOptions = new JButton[] { canContinue, cancel };
} else {
options = new JButton[] { cancel };
closeOptions = new JButton[] { cancel };
}
dd.setOptions(options);
dd.setClosingOptions(closeOptions);
dd.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
final Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
JDialog jdlg = (JDialog) dlg;
jdlg.getRootPane().setDefaultButton(cancel);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
dlg.setVisible(true);
}
});
} catch (InterruptedException ex) {
log.log(Level.INFO, ex.getLocalizedMessage(), ex);
return null;
} catch (InvocationTargetException ex) {
log.log(Level.INFO, ex.getLocalizedMessage(), ex);
return null;
}
if (!canContinue.equals(dd.getValue())) {
if (!cancel.equals(dd.getValue())) {
cancel.doClick();
}
return null;
}
assert canContinue.equals(dd.getValue());
}
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
return inst;
}
use of org.netbeans.modules.autoupdate.ui.ProblemPanel in project netbeans-rcp-lite by outersky.
the class InstallStep method tryPerformDownload.
private boolean tryPerformDownload(final InstallSupport support) {
validator = null;
JLabel detailLabel = null;
try {
ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
if (runInBackground()) {
systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
return handleCancel();
}
});
handle = systemHandle;
} else {
spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
return handleCancel();
}
});
totalUnits = model.getInstallContainer().listAll().size();
processedUnits = 0;
detailLabel.addPropertyChangeListener(TEXT_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
assert TEXT_PROPERTY.equals(evt.getPropertyName()) : "Listens onlo on " + TEXT_PROPERTY + " but was " + evt;
if (evt.getOldValue() != evt.getNewValue()) {
processedUnits++;
if (indeterminateProgress && spareHandleStarted) {
if (processedUnits < totalUnits - 1) {
totalUnits = totalUnits - processedUnits;
spareHandle.switchToDeterminate(totalUnits);
indeterminateProgress = false;
}
}
if (!indeterminateProgress && spareHandleStarted) {
spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
}
}
}
});
}
handle.setInitialDelay(0);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
validator = support.doDownload(handle, Utilities.isGlobalInstallation(), userdirAsFallback);
if (validator == null) {
handleCancel();
return true;
}
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
if (spareHandle != null && spareHandleStarted) {
spareHandle.finish();
spareHandleStarted = false;
}
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
if (OperationException.ERROR_TYPE.PROXY == ex.getErrorType()) {
if (runInBackground()) {
handleCancel();
notifyNetworkProblem(ex);
} else {
JButton tryAgain = new JButton();
// NOI18N
Mnemonics.setLocalizedText(tryAgain, getBundle("InstallStep_NetworkProblem_Continue"));
ProblemPanel problem = new ProblemPanel(// NOI18N
getBundle("InstallStep_NetworkProblem_Text", ex.getLocalizedMessage()), new JButton[] { tryAgain, model.getCancelButton(wd) });
Object ret = problem.showNetworkProblemDialog();
if (tryAgain.equals(ret)) {
// try again
return false;
} else if (DialogDescriptor.CLOSED_OPTION.equals(ret)) {
model.getCancelButton(wd).doClick();
}
}
} else if (OperationException.ERROR_TYPE.WRITE_PERMISSION == ex.getErrorType()) {
if (runInBackground()) {
UpdateElement culprit = findCulprit(ex.getMessage());
handleCancel();
notifyWritePermissionProblem(ex, culprit);
} else {
JButton cancel = new JButton();
Mnemonics.setLocalizedText(cancel, cancel());
JButton install = new JButton();
Mnemonics.setLocalizedText(install, install());
UpdateElement culprit = findCulprit(ex.getMessage());
ProblemPanel problem = new ProblemPanel(ex, culprit, false);
Object ret = problem.showWriteProblemDialog();
if (install.equals(ret)) {
// install anyway
userdirAsFallback = true;
return false;
} else {
model.getCancelButton(wd).doClick();
}
}
} else {
// general problem, show more
String pluginName = detailLabel == null || detailLabel.getText().length() == 0 ? getBundle("InstallStep_DownloadProblem_SomePlugins") : detailLabel.getText();
String message = getBundle("InstallStep_DownloadProblem", pluginName, ex.getLocalizedMessage());
Exceptions.attachLocalizedMessage(ex, message);
log.log(Level.SEVERE, null, ex);
handleCancel();
}
}
return true;
}
Aggregations