Search in sources :

Example 11 with ProgressHandle

use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.

the class OptionsChooserPanel method showExportDialog.

/**
 * Shows panel for export of options.
 */
@NbBundle.Messages({ "ProgressHandle_Export_DisplayName=Exporting Options", "# {0} - path where the exported options are saved", "Export_Notification_DetailsText=File saved at {0}" })
public static void showExportDialog() {
    if (exportTask != null && !exportTask.isFinished()) {
        return;
    }
    // NOI18N
    LOGGER.fine("showExportDialog");
    File sourceUserdir = Places.getUserDirectory();
    final OptionsChooserPanel optionsChooserPanel = new OptionsChooserPanel();
    optionsChooserPanel.panelType = PanelType.EXPORT;
    optionsChooserPanel.setOptionsExportModel(new OptionsExportModel(sourceUserdir));
    optionsChooserPanel.loadOptions();
    optionsChooserPanel.txtFile.setText(getDefaultUserdirRoot().concat(File.separator));
    optionsChooserPanel.txtFile.getDocument().addDocumentListener(new DocumentListener() {

        public void insertUpdate(DocumentEvent e) {
            optionsChooserPanel.dialogDescriptor.setValid(optionsChooserPanel.isPanelValid());
        }

        public void removeUpdate(DocumentEvent e) {
            optionsChooserPanel.dialogDescriptor.setValid(optionsChooserPanel.isPanelValid());
        }

        public void changedUpdate(DocumentEvent e) {
            optionsChooserPanel.dialogDescriptor.setValid(optionsChooserPanel.isPanelValid());
        }
    });
    DialogDescriptor dd = new DialogDescriptor(optionsChooserPanel, NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.export.title"), true, new Object[] { DialogDescriptor.OK_OPTION, DialogDescriptor.CANCEL_OPTION }, DialogDescriptor.OK_OPTION, DialogDescriptor.DEFAULT_ALIGN, null, null);
    // add bottom user notification area
    dd.createNotificationLineSupport();
    dd.setValid(false);
    ExportConfirmationPanel exportConfirmationPanel = null;
    if (!ExportConfirmationPanel.getSkipOption()) {
        exportConfirmationPanel = new ExportConfirmationPanel();
        final ExportConfirmationPanel finalExportConfirmationPanel = exportConfirmationPanel;
        dd.setButtonListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == DialogDescriptor.OK_OPTION) {
                    String passwords = NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.export.passwords.displayName");
                    Enumeration dfs = ((DefaultMutableTreeNode) treeModel.getRoot()).depthFirstEnumeration();
                    while (dfs.hasMoreElements()) {
                        Object nodeObj = dfs.nextElement();
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodeObj;
                        Object userObject = node.getUserObject();
                        if (userObject instanceof OptionsExportModel.Item) {
                            if (((OptionsExportModel.Item) userObject).getDisplayName().equals(passwords)) {
                                if (treeDataProvider.isSelected(nodeObj)) {
                                    // show confirmation dialog when user click OK and All/Passwords/Passwords item is selected
                                    finalExportConfirmationPanel.showConfirmation();
                                }
                            }
                        }
                    }
                }
            }
        });
    }
    optionsChooserPanel.setDialogDescriptor(dd);
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    if (DialogDescriptor.OK_OPTION.equals(dd.getValue())) {
        if (exportConfirmationPanel != null && !exportConfirmationPanel.confirmed()) {
            // NOI18N
            LOGGER.fine("Export canceled.");
            return;
        }
        // NOI18N
        Action save = Actions.forID("Window", "org.netbeans.core.windows.actions.SaveWindowsAction");
        if (save != null) {
            save.actionPerformed(new ActionEvent(optionsChooserPanel, 0, ""));
        }
        String selectedFilePath = optionsChooserPanel.getSelectedFilePath();
        if (selectedFilePath.endsWith("/")) {
            // NOI18N
            // name zip file after last folder
            // NOI18N
            selectedFilePath = selectedFilePath.substring(0, selectedFilePath.lastIndexOf("/"));
            // NOI18N
            String zipName = selectedFilePath.substring(selectedFilePath.lastIndexOf("/") + 1);
            // NOI18N
            selectedFilePath = selectedFilePath.concat("/").concat(zipName).concat(".zip");
        }
        if (!selectedFilePath.endsWith(".zip")) {
            // NOI18N
            // NOI18N
            selectedFilePath = selectedFilePath.concat(".zip");
        }
        final String targetPath = selectedFilePath;
        // NOI18N
        RequestProcessor RP = new RequestProcessor("OptionsChooserPanel Export", 1);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                // to avoid false possitives during import, find the items that are explicitly selected by the user for export
                Enumeration dfs = ((DefaultMutableTreeNode) treeModel.getRoot()).depthFirstEnumeration();
                ArrayList<String> enabledItems = new ArrayList<String>();
                while (dfs.hasMoreElements()) {
                    Object userObject = ((DefaultMutableTreeNode) dfs.nextElement()).getUserObject();
                    if (userObject instanceof OptionsExportModel.Category) {
                        OptionsExportModel.Category category = (OptionsExportModel.Category) userObject;
                        if (!category.getState().equals(OptionsExportModel.State.DISABLED)) {
                            List<OptionsExportModel.Item> items = ((OptionsExportModel.Category) userObject).getItems();
                            for (OptionsExportModel.Item item : items) {
                                if (item.isEnabled()) {
                                    enabledItems.add(category.getDisplayName().concat(item.getDisplayName()));
                                }
                            }
                        }
                    }
                }
                optionsChooserPanel.getOptionsExportModel().doExport(new File(targetPath), enabledItems);
                NotificationDisplayer.getDefault().notify(// NOI18N
                NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.export.status.text"), OPTIONS_ICON, Bundle.Export_Notification_DetailsText(targetPath), null);
                // NOI18N
                LOGGER.fine("Export finished.");
            }
        };
        exportTask = RP.create(runnable);
        final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.ProgressHandle_Export_DisplayName(), exportTask);
        exportTask.addTaskListener(new TaskListener() {

            @Override
            public void taskFinished(org.openide.util.Task task) {
                ph.finish();
            }
        });
        ph.start();
        exportTask.schedule(0);
    }
}
Also used : DocumentListener(javax.swing.event.DocumentListener) Action(javax.swing.Action) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) TaskListener(org.openide.util.TaskListener) Enumeration(java.util.Enumeration) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener) ProgressHandle(org.netbeans.api.progress.ProgressHandle) DialogDescriptor(org.openide.DialogDescriptor) File(java.io.File) RequestProcessor(org.openide.util.RequestProcessor)

Example 12 with ProgressHandle

use of org.netbeans.api.progress.ProgressHandle in project nmf-mission-ops-sat by esa.

the class CreateSnapshotAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    ProgressHandle p = ProgressHandleFactory.createHandle("Recording snapshot...");
    p.start();
    logger.log(Level.INFO, "Creating snapshot...");
    SnapshotBuffer buffer = SnapshotManager.getCurrentBuffer();
    buffer.stopBuffering(Options.getSnapshotBufferFinish());
    buffer.writeToFile();
    p.finish();
}
Also used : ProgressHandle(org.netbeans.api.progress.ProgressHandle)

Example 13 with ProgressHandle

use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.

the class Utilities method tryRefreshProviders.

private static boolean tryRefreshProviders(Collection<UpdateUnitProvider> providers, PluginManagerUI manager, boolean force) {
    ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(SettingsTableModel.class, ("Utilities_CheckingForUpdates")));
    JComponent progressComp = ProgressHandleFactory.createProgressComponent(handle);
    JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
    detailLabel.setHorizontalAlignment(SwingConstants.LEFT);
    try {
        manager.setProgressComponent(detailLabel, progressComp);
        handle.setInitialDelay(0);
        handle.start();
        if (providers == null) {
            providers = UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true);
        }
        for (UpdateUnitProvider p : providers) {
            try {
                p.refresh(handle, force);
                showProviderNotification(p);
            } catch (IOException ioe) {
                logger.log(Level.INFO, ioe.getMessage(), ioe);
                JButton cancel = new JButton();
                // NOI18N
                Mnemonics.setLocalizedText(cancel, getBundle("Utilities_NetworkProblem_Cancel"));
                JButton skip = new JButton();
                // NOI18N
                Mnemonics.setLocalizedText(skip, getBundle("Utilities_NetworkProblem_Skip"));
                skip.setEnabled(providers.size() > 1);
                JButton tryAgain = new JButton();
                // NOI18N
                Mnemonics.setLocalizedText(tryAgain, getBundle("Utilities_NetworkProblem_Continue"));
                ProblemPanel problem = new ProblemPanel(// NOI18N
                getBundle("Utilities_NetworkProblem_Text", p.getDisplayName(), ioe.getLocalizedMessage()), new JButton[] { tryAgain, skip, cancel });
                Object ret = problem.showNetworkProblemDialog();
                if (skip.equals(ret)) {
                    // skip UpdateUnitProvider and try next one
                    continue;
                } else if (tryAgain.equals(ret)) {
                    // try again
                    return false;
                }
                return true;
            }
        }
    } finally {
        if (handle != null) {
            handle.finish();
        }
        // XXX: Avoid NPE when called refresh providers on selected units
        // #101836: OperationContainer.contains() sometimes fails
        Containers.initNotify();
        manager.unsetProgressComponent(detailLabel, progressComp);
    }
    return true;
}
Also used : ProgressHandle(org.netbeans.api.progress.ProgressHandle) IOException(java.io.IOException)

Example 14 with ProgressHandle

use of org.netbeans.api.progress.ProgressHandle 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;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) Cancellable(org.openide.util.Cancellable) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) ProgressHandle(org.netbeans.api.progress.ProgressHandle) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 15 with ProgressHandle

use of org.netbeans.api.progress.ProgressHandle in project netbeans-rcp-lite by outersky.

the class Janitor method cleanupAction.

@Messages({ "TIT_CONFIRM_CLEANUP=Confirm Cleanup", "# {0} - the dirname to be cleaned up", "TXT_CONFIRM_CLEANUP=Remove user and cache data for NetBeans {0}?", "# {0} - the dirname to be cleaned up", "LBL_CLEANUP=Removing user and cache dirs of {0}" })
static ActionListener cleanupAction(String name) {
    return new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            JanitorPanel panel = new JanitorPanel(Bundle.TXT_CONFIRM_CLEANUP(name));
            DialogDescriptor descriptor = new DialogDescriptor(panel, Bundle.TIT_CONFIRM_CLEANUP(), true, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.YES_OPTION, null);
            if (DialogDescriptor.YES_OPTION == DialogDisplayer.getDefault().notify(descriptor)) {
                JANITOR_RP.post(() -> {
                    try (ProgressHandle handle = ProgressHandle.createHandle(Bundle.LBL_CLEANUP(name))) {
                        handle.start();
                        deleteDir(getUserDir(name));
                        deleteDir(getCacheDir(name));
                    }
                });
            }
            Janitor.setEnabled(panel.isEnabledOnStartup());
            Notification nf = CLEANUP_TASKS.get(this);
            if (nf != null) {
                nf.clear();
            }
        }
    };
}
Also used : ActionListener(java.awt.event.ActionListener) ProgressHandle(org.netbeans.api.progress.ProgressHandle) ActionEvent(java.awt.event.ActionEvent) Notification(org.openide.awt.Notification) Messages(org.openide.util.NbBundle.Messages)

Aggregations

ProgressHandle (org.netbeans.api.progress.ProgressHandle)15 JLabel (javax.swing.JLabel)7 JComponent (javax.swing.JComponent)6 OperationException (org.netbeans.api.autoupdate.OperationException)6 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)5 ArrayList (java.util.ArrayList)4 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 IOException (java.io.IOException)3 Installer (org.netbeans.api.autoupdate.InstallSupport.Installer)3 DialogDescriptor (org.openide.DialogDescriptor)3 Cancellable (org.openide.util.Cancellable)3 Dialog (java.awt.Dialog)2 Pattern (java.util.regex.Pattern)2 JButton (javax.swing.JButton)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 Validator (org.netbeans.api.autoupdate.InstallSupport.Validator)2