use of org.netbeans.api.progress.ProgressHandle in project syncope by apache.
the class ResourceExplorerTopComponent method componentOpened.
// End of variables declaration//GEN-END:variables
@Override
public void componentOpened() {
// look for connection preferences
Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class);
if (StringUtils.isBlank(prefs.get("scheme", null)) || StringUtils.isBlank(prefs.get("host", null)) || StringUtils.isBlank(prefs.get("port", null)) || StringUtils.isBlank(prefs.get("username", null)) || StringUtils.isBlank(prefs.get("password", null))) {
new ServerDetailsView(null, true).setVisible(true);
}
try {
mailTemplateManagerService = ResourceConnector.getMailTemplateManagerService();
reportTemplateManagerService = ResourceConnector.getReportTemplateManagerService();
// init tree, because on close it is reset
initTemplatesTree();
// Load templates
LOG.info("Loading Apache Syncope templates...");
Runnable tsk = new Runnable() {
@Override
public void run() {
final ProgressHandle progr = ProgressHandle.createHandle("Loading Templates", new Cancellable() {
@Override
public boolean cancel() {
return true;
}
});
progr.start();
progr.progress("Loading Templates.");
addMailTemplates();
addReportXslts();
progr.finish();
}
};
REQUEST_PROCESSOR.post(tsk);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE);
ServerDetailsView serverDetails = getRefreshServerDetails();
}
Runnable tsk = new Runnable() {
@Override
public void run() {
final ProgressHandle progr = ProgressHandle.createHandle("Loading Templates", new Cancellable() {
@Override
public boolean cancel() {
return true;
}
});
progr.start();
progr.progress("Loading Templates.");
addMailTemplates();
addReportXslts();
progr.finish();
}
};
RequestProcessor.getDefault().post(tsk);
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class ModuleInstallerSupport method installPlugins.
public Object installPlugins(final String displayName, Set<String> cnbs) throws OperationException {
Collection<UpdateUnit> units = findModules(cnbs);
if (units == null) {
final String searchMessage = displayName != null ? searching_handle_single(displayName) : searching_handle();
final String resolveTitle = displayName != null ? resolve_title_single(displayName) : resolve_title();
final ProgressHandle handle = ProgressHandleFactory.createHandle(searchMessage);
initButtons();
final DialogDescriptor searching = new DialogDescriptor(searchingPanel(new JLabel(searchMessage), ProgressHandleFactory.createProgressComponent(handle)), resolveTitle, true, null);
handle.setInitialDelay(0);
handle.start();
searching.setOptions(new Object[] { NotifyDescriptor.CANCEL_OPTION });
searching.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
final Dialog dlg = DialogDisplayer.getDefault().createDialog(searching);
RP.post(new Runnable() {
@Override
public void run() {
// May be first start, when no update lists have yet been downloaded.
try {
for (UpdateUnitProvider p : UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true)) {
p.refresh(handle, true);
}
// close searching
dlg.dispose();
} catch (IOException ex) {
LOG.log(Level.FINE, ex.getMessage(), ex);
if (!dlg.isVisible()) {
LOG.fine("dialog not visible => do nothing");
return;
}
DialogDescriptor networkProblem = new DialogDescriptor(// message
problemPanel(resolveTitle, networkproblem_message()), // title
networkproblem_header(), // modal
true, null);
networkProblem.setOptions(new Object[] { tryAgain, proxySettings, NotifyDescriptor.CANCEL_OPTION });
networkProblem.setAdditionalOptions(closingOptions);
networkProblem.setClosingOptions(fullClosingOptions);
networkProblem.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
Dialog networkProblemDialog = DialogDisplayer.getDefault().createDialog(networkProblem);
networkProblemDialog.setVisible(true);
Object answer = networkProblem.getValue();
if (NotifyDescriptor.CANCEL_OPTION.equals(answer) || Arrays.asList(closingOptions).contains(answer) || answer.equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
{
LOG.fine("cancel network problem dialog");
searching.setValue(answer);
dlg.dispose();
} else if (tryAgain.equals(answer)) {
LOG.fine("try again searching");
RP.post(this);
} else {
assert false : "Unknown " + answer;
}
}
}
});
dlg.setVisible(true);
handle.finish();
if (NotifyDescriptor.CANCEL_OPTION.equals(searching.getValue()) || searching.getValue().equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
{
LOG.log(Level.FINE, "user canceled searching for {0}", cnbs);
return showNoDownloadDialog(displayName, cnbs);
} else if (Arrays.asList(closingOptions).contains(searching.getValue())) {
return searching.getValue();
}
units = findModules(cnbs);
if (units == null) {
LOG.log(Level.FINE, "could not find {0} on any update site", cnbs);
return showNoDownloadDialog(displayName, cnbs);
}
}
List<UpdateUnit> toHandle = new ArrayList<UpdateUnit>(units);
OperationContainer<OperationSupport> oc = null;
for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
UpdateUnit unit = it.next();
// check if module installed
if (unit.getInstalled() != null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(unit.getInstalled() + " already installed. Is active? " + unit.getInstalled().isEnabled());
}
if (unit.getInstalled().isEnabled()) {
it.remove();
continue;
} else {
if (oc == null) {
oc = OperationContainer.createForEnable();
}
if (!oc.canBeAdded(unit, unit.getInstalled())) {
throw new OperationException(OperationException.ERROR_TYPE.ENABLE, "could not add " + unit.getInstalled() + " for activation");
}
for (UpdateElement req : oc.add(unit.getInstalled()).getRequiredElements()) {
oc.add(req);
}
it.remove();
continue;
}
}
}
if (oc != null) {
ProgressHandle activeHandle = ProgressHandleFactory.createHandle(displayName != null ? active_handle_single(displayName) : active_handle());
Restarter restarter = oc.getSupport().doOperation(activeHandle);
assert restarter == null : "No Restater need to make units active";
}
if (toHandle.isEmpty()) {
return null;
}
OperationContainer<InstallSupport> ocInstall = OperationContainer.createForInstall();
for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
UpdateUnit unit = it.next();
List<UpdateElement> updates = unit.getAvailableUpdates();
if (updates.isEmpty()) {
throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "no updates for " + unit);
}
UpdateElement element = updates.get(0);
if (!ocInstall.canBeAdded(unit, element)) {
throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "could not add " + element + " to updates");
}
for (UpdateElement req : ocInstall.add(element).getRequiredElements()) {
ocInstall.add(req);
}
it.remove();
}
assert toHandle.isEmpty() : "These unit were not handled " + toHandle;
if (!PluginManager.openInstallWizard(ocInstall)) {
LOG.fine("user canceled PM");
return showNoDownloadDialog(displayName, cnbs);
}
return null;
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class ModuleOptions method install.
@NbBundle.Messages({ "# {0} - module name", "# {1} - module version", "MSG_Installing=Installing {0}@{1}", "# {0} - paterns", "MSG_InstallNoMatch=Cannot install. No match for {0}." })
private void install(final Env env, String... pattern) throws CommandException {
if (!initialized()) {
refresh(env);
}
Pattern[] pats = findMatcher(env, pattern);
List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits();
OperationContainer<InstallSupport> operate = OperationContainer.createForInstall();
for (UpdateUnit uu : units) {
if (uu.getInstalled() != null) {
continue;
}
if (!matches(uu.getCodeName(), pats)) {
continue;
}
if (uu.getAvailableUpdates().isEmpty()) {
continue;
}
UpdateElement ue = uu.getAvailableUpdates().get(0);
env.getOutputStream().println(Bundle.MSG_Installing(uu.getCodeName(), ue.getSpecificationVersion()));
operate.add(ue);
}
final InstallSupport support = operate.getSupport();
if (support == null) {
env.getOutputStream().println(Bundle.MSG_InstallNoMatch(Arrays.asList(pats)));
return;
}
try {
// NOI18N
env.getOutputStream().println("modules=" + operate.listAll().size());
// NOI18N
ProgressHandle downloadHandle = new CLIInternalHandle("downloading-modules", env).createProgressHandle();
downloadHandle.setInitialDelay(0);
final Validator res1 = support.doDownload(downloadHandle, null, false);
Installer res2 = support.doValidate(res1, null);
// NOI18N
ProgressHandle installHandle = new CLIInternalHandle("installing-modules", env).createProgressHandle();
installHandle.setInitialDelay(0);
Restarter res3 = support.doInstall(res2, installHandle);
if (res3 != null) {
support.doRestart(res3, null);
}
} catch (OperationException ex) {
// a hack
if (OperationException.ERROR_TYPE.INSTALL.equals(ex.getErrorType())) {
// probably timeout of loading
env.getErrorStream().println(ex.getLocalizedMessage());
throw (CommandException) new CommandException(34, ex.getMessage()).initCause(ex);
} else {
try {
support.doCancel();
throw (CommandException) new CommandException(32, ex.getMessage()).initCause(ex);
} catch (OperationException ex1) {
throw (CommandException) new CommandException(32, ex1.getMessage()).initCause(ex1);
}
}
}
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class ModuleOptions method updateModules.
@NbBundle.Messages({ "MSG_UpdateNotFound=Updates not found.", "# {0} - pattern", "MSG_UpdateNoMatchPattern=Nothing to update. The pattern {0} has no match among available updates.", "# {0} - module name", "# {1} - installed version", "# {2} - available version", "MSG_Update=Will update {0}@{1} to version {2}", "# {0} - plugin name", "MSG_Download=Downloading {0}" })
private void updateModules(final Env env, String... pattern) throws CommandException {
if (!initialized()) {
refresh(env);
}
Pattern[] pats = findMatcher(env, pattern);
List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
final Collection<String> firstClass = getFirstClassModules();
boolean firstClassHasUpdates = false;
OperationContainer<InstallSupport> operate = OperationContainer.createForUpdate();
if (!firstClass.isEmpty() && pattern.length == 0) {
for (UpdateUnit uu : units) {
if (uu.getInstalled() == null) {
continue;
}
final List<UpdateElement> updates = uu.getAvailableUpdates();
if (updates.isEmpty()) {
continue;
}
if (!firstClass.contains(uu.getCodeName())) {
continue;
}
final UpdateElement ue = updates.get(0);
env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
if (operate.canBeAdded(uu, ue)) {
LOG.fine(" ... update " + uu.getInstalled() + " -> " + ue);
firstClassHasUpdates = true;
OperationInfo<InstallSupport> info = operate.add(ue);
if (info != null) {
Set<UpdateElement> requiredElements = info.getRequiredElements();
LOG.fine(" ... add required elements: " + requiredElements);
operate.add(requiredElements);
}
}
}
}
if (!firstClassHasUpdates) {
for (UpdateUnit uu : units) {
if (uu.getInstalled() == null) {
continue;
}
final List<UpdateElement> updates = uu.getAvailableUpdates();
if (updates.isEmpty()) {
continue;
}
if (pattern.length > 0 && !matches(uu.getCodeName(), pats)) {
continue;
}
final UpdateElement ue = updates.get(0);
env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
if (operate.canBeAdded(uu, ue)) {
LOG.fine(" ... update " + uu.getInstalled() + " -> " + ue);
OperationInfo<InstallSupport> info = operate.add(ue);
if (info != null) {
Set<UpdateElement> requiredElements = info.getRequiredElements();
LOG.fine(" ... add required elements: " + requiredElements);
operate.add(requiredElements);
}
}
}
}
final InstallSupport support = operate.getSupport();
if (support == null) {
env.getOutputStream().println(pats == null || pats.length == 0 ? Bundle.MSG_UpdateNotFound() : Bundle.MSG_UpdateNoMatchPattern(Arrays.asList(pats)));
// NOI18N
env.getOutputStream().println("updates=0");
return;
}
// NOI18N
env.getOutputStream().println("updates=" + operate.listAll().size());
// NOI18N
ProgressHandle downloadHandle = new CLIInternalHandle("downloading-updates", env).createProgressHandle();
downloadHandle.setInitialDelay(0);
try {
final Validator res1 = support.doDownload(downloadHandle, null, false);
Installer res2 = support.doValidate(res1, null);
// NOI18N
ProgressHandle installHandle = new CLIInternalHandle("installing-updates", env).createProgressHandle();
installHandle.setInitialDelay(0);
Restarter res3 = support.doInstall(res2, installHandle);
if (res3 != null) {
support.doRestart(res3, null);
}
} catch (OperationException ex) {
try {
support.doCancel();
throw (CommandException) new CommandException(33, ex.getMessage()).initCause(ex);
} catch (OperationException ex1) {
throw (CommandException) new CommandException(33, ex1.getMessage()).initCause(ex1);
}
}
}
use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.
the class InstallStep method handleInstall.
private Restarter handleInstall(Installer i, final InstallSupport support) {
if (canceled) {
log.fine("Quit handleInstall() because an previous installation was canceled.");
return null;
}
installException = null;
component.setHeadAndContent(getBundle(HEAD_INSTALL), getBundle(CONTENT_INSTALL));
model.modifyOptionsForDisabledCancel(wd);
ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
if (runInBackground()) {
systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
handle = systemHandle;
} else {
spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
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);
Restarter r = null;
boolean success = false;
try {
r = support.doInstall(i, handle);
success = true;
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Unsuccessful", ex.getLocalizedMessage())));
installException = ex;
}
if (success) {
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
}
if (spareHandle != null && spareHandleStarted) {
spareHandle.finish();
}
return r;
}
Aggregations