Search in sources :

Example 1 with JOptionPaneActionHandler

use of net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler in project processdash by dtuma.

the class TaskScheduleChart method showSaveAsDialog.

private TaskScheduleChartSettings showSaveAsDialog(TaskScheduleChartSettings currentSettings, String chartID) {
    String title = resources.getString("Configure.Save_As.Window_Title");
    String namePrompt = resources.getString("Configure.Save_As.Name_Prompt");
    JTextField chartNameField = new JTextField();
    if (currentSettings != null)
        chartNameField.setText(currentSettings.getCustomName());
    new JOptionPaneActionHandler().install(chartNameField);
    String scopePrompt = resources.getString("Configure.Save_As.Scope_Prompt");
    ButtonGroup group = new ButtonGroup();
    JRadioButton localScopeButton = new JRadioButton(resources.getString("Configure.Save_As.Scope_Local"));
    group.add(localScopeButton);
    JRadioButton globalScopeButton = new JRadioButton(resources.getString("Configure.Save_As.Scope_Global"));
    group.add(globalScopeButton);
    boolean global = (currentSettings != null && currentSettings.isGlobal());
    (global ? globalScopeButton : localScopeButton).setSelected(true);
    String errorKey = null;
    while (true) {
        BoxUtils errorBox;
        if (errorKey != null) {
            JLabel errorLabel = new JLabel(resources.getString(errorKey));
            errorLabel.setForeground(Color.RED);
            errorBox = BoxUtils.hbox(20, errorLabel);
        } else {
            errorBox = BoxUtils.hbox();
        }
        Object[] message = { namePrompt, BoxUtils.hbox(20, chartNameField), new JOptionPaneTweaker.GrabFocus(chartNameField), errorBox, scopePrompt, BoxUtils.hbox(20, localScopeButton), BoxUtils.hbox(20, globalScopeButton) };
        int userChoice = JOptionPane.showConfirmDialog(configurationDialog, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (userChoice != JOptionPane.OK_OPTION)
            return null;
        String chartName = chartNameField.getText();
        chartName = (chartName == null ? "" : chartName.trim());
        if (chartName.length() == 0) {
            errorKey = "Configure.Save_As.Name_Missing";
            continue;
        }
        TaskScheduleChartSettings result = new TaskScheduleChartSettings();
        if (localScopeButton.isSelected())
            result.setTaskListID(taskList.getID());
        result.setChartID(chartID);
        result.setCustomName(chartName);
        if (result.hasSameNameAs(currentSettings) == false && chartNameIsTaken(chartName)) {
            errorKey = "Configure.Save_As.Duplicate_Name";
            continue;
        }
        return result;
    }
}
Also used : JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) JOptionPaneActionHandler(net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler) JRadioButton(javax.swing.JRadioButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) BoxUtils(net.sourceforge.processdash.ui.lib.BoxUtils) Point(java.awt.Point) ButtonGroup(javax.swing.ButtonGroup) EventObject(java.util.EventObject)

Example 2 with JOptionPaneActionHandler

use of net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler in project processdash by dtuma.

the class TaskScheduleChooser method getTemplateName.

protected String getTemplateName(Object parent, String title, String prompt, String initialTaskName, boolean showRollupOptions) {
    String taskName = "";
    Object message = prompt, button;
    Object[] options;
    JComboBox rollupOption = null;
    if (showRollupOptions) {
        String[] rollupOptions = new String[2];
        rollupOptions[0] = resources.getString("Create_Schedule_Option");
        rollupOptions[1] = resources.getString("Create_Rollup_Option");
        rollupOption = new JComboBox(rollupOptions);
        options = new Object[] { rollupOption, new JLabel("      "), OK, CANCEL };
    } else
        options = new Object[] { OK, CANCEL };
    JTextField inputField = new JTextField(initialTaskName);
    inputField.selectAll();
    new JOptionPaneActionHandler(OK).install(inputField);
    Component parentComponent = null;
    if (parent instanceof Component)
        parentComponent = (Component) parent;
    while (true) {
        JOptionPane optionPane = new JOptionPane(new Object[] { message, inputField }, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options);
        optionPane.createDialog(parentComponent, title).setVisible(true);
        button = optionPane.getValue();
        if (!OK.equals(button))
            // user cancel
            return null;
        taskName = (String) inputField.getText();
        taskName = taskName.trim();
        String errorMessage = checkNewTemplateName(taskName, dash.getData());
        if (errorMessage == null)
            break;
        else
            message = new String[] { errorMessage, prompt };
    }
    if (rollupOption != null && rollupOption.getSelectedIndex() == 1)
        taskName = ROLLUP_PREFIX + taskName;
    return taskName;
}
Also used : JOptionPaneActionHandler(net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) Component(java.awt.Component) JOptionPane(javax.swing.JOptionPane)

Example 3 with JOptionPaneActionHandler

use of net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler in project processdash by dtuma.

the class QuickSelectTaskAction method selectTask.

private void selectTask() {
    if (taskProvider == null || activeTaskModel == null)
        throw new IllegalStateException("Object not yet initialized");
    TreeTableModel tasks = taskProvider.getTaskSelectionChoices();
    final JFilterableTreeComponent selector = new JFilterableTreeComponent(tasks, resources.getString("Choose_Task.Find"), false);
    final Object nodeToSelect = taskProvider.getTreeNodeForPath(activeTaskModel.getPath());
    loadPrefs(selector);
    selector.setMatchEntirePath(true);
    TaskCompletionRenderer rend = null;
    if (parentComponent instanceof DashboardContext)
        rend = new TaskCompletionRenderer(selector, (DashboardContext) parentComponent);
    new JOptionPaneActionHandler().install(selector);
    Object[] message = new Object[] { resources.getString("Choose_Task.Prompt"), selector, new JOptionPaneTweaker.MakeResizable(), new JOptionPaneTweaker.GrabFocus(selector.getFilterTextField()), new JOptionPaneTweaker(50) {

        public void doTweak(JDialog dialog) {
            if (nodeToSelect != null)
                selector.setAnchorSelectedNode(nodeToSelect);
        }
    } };
    int userChoice = JOptionPane.showConfirmDialog(parentComponent, message, resources.getString("Choose_Task.Title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    savePrefs(selector);
    if (rend != null)
        rend.dispose();
    if (userChoice != JOptionPane.OK_OPTION)
        return;
    Object newTask = selector.getSelectedLeaf();
    if (newTask == null)
        return;
    String newPath = taskProvider.getPathForTreeNode(newTask);
    if (StringUtils.hasValue(newPath))
        activeTaskModel.setPath(newPath);
}
Also used : DashboardContext(net.sourceforge.processdash.DashboardContext) JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) JOptionPaneActionHandler(net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler) TreeTableModel(net.sourceforge.processdash.ui.lib.TreeTableModel) JFilterableTreeComponent(net.sourceforge.processdash.ui.lib.JFilterableTreeComponent) JDialog(javax.swing.JDialog)

Aggregations

JOptionPaneActionHandler (net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler)3 JLabel (javax.swing.JLabel)2 JTextField (javax.swing.JTextField)2 JOptionPaneTweaker (net.sourceforge.processdash.ui.lib.JOptionPaneTweaker)2 Component (java.awt.Component)1 Point (java.awt.Point)1 EventObject (java.util.EventObject)1 ButtonGroup (javax.swing.ButtonGroup)1 JComboBox (javax.swing.JComboBox)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 JRadioButton (javax.swing.JRadioButton)1 DashboardContext (net.sourceforge.processdash.DashboardContext)1 BoxUtils (net.sourceforge.processdash.ui.lib.BoxUtils)1 JFilterableTreeComponent (net.sourceforge.processdash.ui.lib.JFilterableTreeComponent)1 TreeTableModel (net.sourceforge.processdash.ui.lib.TreeTableModel)1