use of org.netbeans.api.progress.ProgressHandle 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.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class UnitTab method reloadTask.
private Task reloadTask(final boolean force) {
final Runnable checkUpdates = new Runnable() {
@Override
public void run() {
ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(UnitTab.class, ("UnitTab_ReloadAction")));
JComponent progressComp = ProgressHandleFactory.createProgressComponent(handle);
JLabel detailLabel = new JLabel(NbBundle.getMessage(UnitTab.class, "UnitTab_PrepareReloadAction"));
manager.setProgressComponent(detailLabel, progressComp);
handle.setInitialDelay(0);
handle.start();
manager.initTask.waitFinished();
setWaitingState(true);
if (getDownloadSizeTask != null && !getDownloadSizeTask.isFinished()) {
if (getDownloadSizeTask.getDelay() > 0) {
getDownloadSizeTask.cancel();
} else {
getDownloadSizeTask.waitFinished();
}
}
final int row = getSelectedRow();
final Map<String, Boolean> state = UnitCategoryTableModel.captureState(model.getUnits());
if (model instanceof LocallyDownloadedTableModel) {
((LocallyDownloadedTableModel) model).removeInstalledUnits();
((LocallyDownloadedTableModel) model).setUnits(null);
}
manager.unsetProgressComponent(detailLabel, progressComp);
Utilities.presentRefreshProviders(manager, force);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
fireUpdataUnitChange();
UnitCategoryTableModel.restoreState(model.getUnits(), state, model.isMarkedAsDefault());
restoreSelectedRow(row);
refreshState();
setWaitingState(false);
}
});
}
};
return Utilities.startAsWorkerThread(checkUpdates);
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class AutoupdateCheckScheduler method checkUpdateElements.
public static Collection<UpdateElement> checkUpdateElements(OperationType type, Collection<String> problems, boolean forceReload, Collection<UpdateElement> visibleUpdateElement) {
// check
err.log(Level.FINEST, "Check UpdateElements for " + type);
if (forceReload) {
// NOI18N
ProgressHandle dummyHandler = ProgressHandleFactory.createHandle("dummy-check-for-updates");
ProgressHandleFactory.createProgressComponent(dummyHandler);
dummyHandler.start();
Collection<String> updateProblems = refreshUpdateCenters(dummyHandler);
if (problems != null && updateProblems != null) {
problems.addAll(updateProblems);
}
}
List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
boolean handleUpdates = OperationType.UPDATE == type;
Collection<UnitCategory> cats = handleUpdates ? Utilities.makeUpdateCategories(units, false) : Utilities.makeAvailableCategories(units, false);
if (cats == null || cats.isEmpty()) {
err.log(Level.FINE, "findUpdateElements(" + type + ") doesn't find any elements.");
return null;
}
// 1. try to install all available updates
Collection<UpdateElement> updates = new HashSet<UpdateElement>();
boolean somePendingElements = false;
boolean someBrokenDependencies = false;
OperationContainer<InstallSupport> container = handleUpdates ? OperationContainer.createForUpdate() : OperationContainer.createForInstall();
List<UpdateElement> elements = new ArrayList<UpdateElement>();
for (UnitCategory cat : cats) {
for (Unit u : cat.getUnits()) {
if (u instanceof Unit.Available) {
elements.add(((Unit.Available) u).getRelevantElement());
} else if (u instanceof Unit.CompoundUpdate) {
for (UpdateUnit uu : ((Unit.CompoundUpdate) u).getUpdateUnits()) {
elements.add(uu.getAvailableUpdates().get(0));
}
if (((Unit.CompoundUpdate) u).getRealUpdate() != null) {
elements.add(((Unit.CompoundUpdate) u).getRealUpdate());
}
} else if (u instanceof Unit.Update) {
elements.add(((Unit.Update) u).getRelevantElement());
}
}
}
for (UpdateElement element : elements) {
if (!somePendingElements) {
if (container.canBeAdded(element.getUpdateUnit(), element)) {
OperationInfo<InstallSupport> operationInfo = container.add(element);
if (operationInfo == null) {
updates.add(element);
continue;
}
Collection<UpdateElement> reqs = new HashSet<UpdateElement>(operationInfo.getRequiredElements());
Collection<String> brokenDeps = operationInfo.getBrokenDependencies();
if (!brokenDeps.isEmpty()) {
err.log(Level.WARNING, // NOI18N
"Plugin " + operationInfo + " cannot be installed because some dependencies cannot be satisfied: " + // NOI18N
brokenDeps);
someBrokenDependencies = true;
break;
}
for (UpdateElement tmpEl : reqs) {
if (tmpEl.getUpdateUnit().isPending()) {
err.log(Level.WARNING, // NOI18N
"Plugin " + operationInfo.getUpdateElement() + " depends on " + tmpEl + " in pending state.");
somePendingElements = true;
updates = Collections.emptySet();
break;
}
}
if (!somePendingElements) {
container.add(reqs);
updates.add(element);
}
}
}
}
if (!somePendingElements && !container.listInvalid().isEmpty()) {
err.log(Level.WARNING, // NOI18N
"Plugins " + updates + " cannot be installed, Install Container contains invalid elements " + // NOI18N
container.listInvalid());
}
if (!somePendingElements && someBrokenDependencies) {
// 2. if some problem then try one by one
updates = new HashSet<UpdateElement>();
for (UpdateElement element : elements) {
OperationContainer<InstallSupport> oc = handleUpdates ? OperationContainer.createForUpdate() : OperationContainer.createForInstall();
UpdateUnit unit = element.getUpdateUnit();
if (oc.canBeAdded(unit, element)) {
OperationInfo<InstallSupport> operationInfo = oc.add(element);
if (operationInfo == null) {
updates.add(element);
continue;
}
boolean skip = false;
Collection<UpdateElement> reqs = new HashSet<UpdateElement>(operationInfo.getRequiredElements());
for (UpdateElement tmpEl : reqs) {
if (tmpEl.getUpdateUnit().isPending()) {
err.log(Level.WARNING, // NOI18N
"Plugin " + element + " depends on " + tmpEl + " in pending state.");
skip = true;
}
}
if (skip) {
continue;
}
oc.add(reqs);
Collection<String> brokenDeps = new HashSet<String>();
for (OperationInfo<InstallSupport> info : oc.listAll()) {
brokenDeps.addAll(info.getBrokenDependencies());
}
if (brokenDeps.isEmpty() && oc.listInvalid().isEmpty()) {
updates.add(element);
} else {
oc.removeAll();
if (!brokenDeps.isEmpty()) {
err.log(Level.WARNING, // NOI18N
"Plugin " + element + " cannot be installed because some dependencies cannot be satisfied: " + // NOI18N
brokenDeps);
} else {
err.log(Level.WARNING, // NOI18N
"Plugin " + element + " cannot be installed, Install Container contains invalid elements " + // NOI18N
oc.listInvalid());
}
}
}
}
}
// if any then notify updates
if (visibleUpdateElement == null) {
err.log(Level.FINE, "findUpdateElements(" + type + ") returns " + updates.size() + " elements.");
return updates;
} else {
for (UnitCategory cat : cats) {
for (Unit u : cat.getUnits()) {
assert u instanceof Unit.Update : u + " has to be instanceof Unit.Update";
if (u instanceof Unit.Update) {
visibleUpdateElement.add(((Unit.Update) u).getRelevantElement());
}
}
}
err.log(Level.FINE, "findUpdateElements(" + type + ") returns " + visibleUpdateElement.size() + " visible elements (" + updates.size() + " in all)");
return updates;
}
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class CustomHandleStep method handleOperation.
private boolean handleOperation() {
final OperationSupport support = model.getCustomHandledContainer().getSupport();
assert support != null;
passed = false;
Runnable performOperation = new Runnable() {
public void run() {
try {
final ProgressHandle handle = ProgressHandleFactory.createHandle(isInstall ? getBundle("CustomHandleStep_Install_InstallingPlugins") : getBundle("CustomHandleStep_Uninstall_UninstallingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
handle.setInitialDelay(0);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
restarter = support.doOperation(handle);
passed = true;
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("CustomHandleStep_Done")));
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
passed = false;
errorMessage = ex.getLocalizedMessage();
}
}
};
performOperation.run();
return passed;
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class UninstallStep method handleAction.
@NbBundle.Messages({ "UninstallStep_NullSupport_NullElements=Not found any elements for that operation.", "# {0} - invalid elements", "UninstallStep_NullSupport_InvalidElements=Found invalid element(s) {0} for that operation.", "UninstallStep_ProgressName_Uninstall=Uninstalling plugins", "UninstallStep_ProgressName_Activate=Activating plugins", "UninstallStep_ProgressName_Deactivate=Deactivating plugins", "UninstallStep_Done=Done.", "# {0} - A error message", "UninstallStep_Failed=Failed. {0}" })
private Restarter handleAction() throws OperationException {
assert model.getBaseContainer() != null : "getBaseContainers() returns not null container.";
support = (OperationSupport) model.getBaseContainer().getSupport();
assert support != null : "OperationSupport cannot be null because OperationContainer " + "contains elements: " + model.getBaseContainer().listAll() + " and invalid elements " + model.getBaseContainer().listInvalid();
if (support == null) {
err.log(Level.WARNING, "OperationSupport cannot be null because OperationContainer contains elements: " + "{0} and invalid elements {1}", new Object[] { model.getBaseContainer().listAll(), model.getBaseContainer().listInvalid() });
if (!model.getBaseContainer().listInvalid().isEmpty()) {
// cannot continue if there are invalid elements
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, UninstallStep_NullSupport_InvalidElements(model.getBaseContainer().listInvalid()));
} else if (model.getBaseContainer().listAll().isEmpty()) {
// it's weird, there must be any elemets for uninstall
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, UninstallStep_NullSupport_NullElements());
}
throw new OperationException(OperationException.ERROR_TYPE.UNINSTALL, "OperationSupport cannot be null because OperationContainer " + "contains elements: " + model.getBaseContainer().listAll() + " and invalid elements " + model.getBaseContainer().listInvalid());
}
ProgressHandle handle = null;
switch(model.getOperation()) {
case UNINSTALL:
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Uninstall());
break;
case ENABLE:
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Activate());
break;
case DISABLE:
handle = ProgressHandleFactory.createHandle(UninstallStep_ProgressName_Deactivate());
break;
default:
assert false : "Unknown OperationType " + model.getOperation();
}
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
model.modifyOptionsForDisabledCancel(wd);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
Restarter r = null;
try {
r = support.doOperation(handle);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(UninstallStep_Done()));
} catch (OperationException ex) {
err.log(Level.INFO, ex.getMessage(), ex);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(UninstallStep_Failed(ex.getLocalizedMessage())));
throw ex;
}
return r;
}
Aggregations