Lines 11-42
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.mylyn.tasks.ui.wizards; |
12 |
package org.eclipse.mylyn.tasks.ui.wizards; |
13 |
|
13 |
|
14 |
import java.lang.reflect.InvocationTargetException; |
|
|
15 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
16 |
|
15 |
|
17 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
|
18 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
19 |
import org.eclipse.jface.wizard.IWizard; |
16 |
import org.eclipse.jface.wizard.IWizard; |
20 |
import org.eclipse.jface.wizard.WizardDialog; |
17 |
import org.eclipse.jface.wizard.WizardDialog; |
21 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
18 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
|
|
19 |
import org.eclipse.mylyn.internal.provisional.commons.ui.dialogs.BottomButtonWizardDialog; |
22 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.Messages; |
20 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.Messages; |
23 |
import org.eclipse.mylyn.tasks.ui.TasksUiImages; |
21 |
import org.eclipse.mylyn.tasks.ui.TasksUiImages; |
24 |
import org.eclipse.swt.SWT; |
|
|
25 |
import org.eclipse.swt.layout.GridData; |
26 |
import org.eclipse.swt.layout.GridLayout; |
27 |
import org.eclipse.swt.widgets.Button; |
22 |
import org.eclipse.swt.widgets.Button; |
28 |
import org.eclipse.swt.widgets.Composite; |
23 |
import org.eclipse.swt.widgets.Composite; |
29 |
import org.eclipse.swt.widgets.Control; |
|
|
30 |
import org.eclipse.swt.widgets.Label; |
31 |
import org.eclipse.swt.widgets.Shell; |
24 |
import org.eclipse.swt.widgets.Shell; |
32 |
|
25 |
|
33 |
/** |
26 |
/** |
34 |
* Wizard dialog for displaying repository settings page. Necessary so we can add a validate button in the button bar. |
27 |
* Wizard dialog for displaying repository settings page. Necessary so we can add a validate button in the button bar. |
35 |
* |
28 |
* |
36 |
* @author Helen Bershadskaya |
29 |
* @author Helen Bershadskaya |
|
|
30 |
* @author Frank Becker |
37 |
* @since 3.1 |
31 |
* @since 3.1 |
38 |
*/ |
32 |
*/ |
39 |
public class TaskRepositoryWizardDialog extends WizardDialog { |
33 |
public class TaskRepositoryWizardDialog extends BottomButtonWizardDialog { |
40 |
|
34 |
|
41 |
private static final String VALIDATE_BUTTON_KEY = "validate"; //$NON-NLS-1$ |
35 |
private static final String VALIDATE_BUTTON_KEY = "validate"; //$NON-NLS-1$ |
42 |
|
36 |
|
Lines 54-98
Link Here
|
54 |
} |
48 |
} |
55 |
|
49 |
|
56 |
/** |
50 |
/** |
57 |
* Overridden so we can add a validate button to the wizard button bar, if a repository settings page requires it. |
51 |
* Modeled after super.saveAndSetEnabledState(), but that one is private, so create our own |
58 |
* Validate button is added left justified at button bar bottom (next to help image). |
|
|
59 |
* |
52 |
* |
60 |
* @since 3.1 |
53 |
* @since 3.6 |
61 |
*/ |
54 |
*/ |
62 |
@Override |
55 |
@Override |
63 |
protected Control createButtonBar(Composite parent) { |
56 |
protected HashMap<String, Boolean> saveAndSetEnabledStateMylyn() { |
64 |
Composite composite = new Composite(parent, SWT.NONE); |
57 |
HashMap<String, Boolean> savedEnabledState = null; |
65 |
GridLayout layout = new GridLayout(); |
58 |
if (getShell() != null) { |
66 |
layout.numColumns = 0; // create |
59 |
savedEnabledState = new HashMap<String, Boolean>(); |
67 |
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); |
60 |
if (validateServerButton != null && validateServerButton.getShell() == getShell()) { |
68 |
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); |
61 |
savedEnabledState.put(VALIDATE_BUTTON_KEY, validateServerButton.getEnabled()); |
69 |
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); |
62 |
validateServerButton.setEnabled(false); |
70 |
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); |
63 |
} |
71 |
|
|
|
72 |
composite.setLayout(layout); |
73 |
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
74 |
|
75 |
// create help control if needed |
76 |
if (isHelpAvailable()) { |
77 |
createHelpControl(composite); |
78 |
} |
64 |
} |
|
|
65 |
return savedEnabledState; |
66 |
} |
79 |
|
67 |
|
|
|
68 |
/** |
69 |
* Modeled after super.restoreEnabledState() and super.restoreUIState() -- couldn't override those since they are |
70 |
* private, so create our own. Currently only single button to work with, so don't create two separate methods |
71 |
* |
72 |
* @since 3.6 |
73 |
*/ |
74 |
@Override |
75 |
protected void restoreEnabledStateMylyn(HashMap<String, Boolean> savedEnabledState) { |
76 |
if (savedEnabledState != null) { |
77 |
Boolean savedValidateEnabledState = savedEnabledState.get(VALIDATE_BUTTON_KEY); |
78 |
if (validateServerButton != null && savedValidateEnabledState != null) { |
79 |
validateServerButton.setEnabled(savedValidateEnabledState); |
80 |
} |
81 |
} |
82 |
} |
83 |
|
84 |
/** |
85 |
* @since 3.6 |
86 |
*/ |
87 |
@Override |
88 |
protected void createExtraButtons(Composite composite) { |
80 |
validateServerButton = createButton(composite, VALIDATE_BUTTON_ID, |
89 |
validateServerButton = createButton(composite, VALIDATE_BUTTON_ID, |
81 |
Messages.AbstractRepositorySettingsPage_Validate_Settings, false); |
90 |
Messages.AbstractRepositorySettingsPage_Validate_Settings, false); |
82 |
validateServerButton.setImage(CommonImages.getImage(TasksUiImages.REPOSITORY_VALIDATE)); |
91 |
validateServerButton.setImage(CommonImages.getImage(TasksUiImages.REPOSITORY_VALIDATE)); |
83 |
validateServerButton.setVisible(false); |
92 |
validateServerButton.setVisible(false); |
84 |
setButtonLayoutData(validateServerButton); |
93 |
setButtonLayoutData(validateServerButton); |
85 |
Label filler = new Label(composite, SWT.NONE); |
|
|
86 |
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); |
87 |
((GridLayout) composite.getLayout()).numColumns++; |
88 |
|
89 |
super.createButtonsForButtonBar(composite); |
90 |
|
91 |
return composite; |
92 |
} |
94 |
} |
93 |
|
95 |
|
|
|
96 |
/** |
97 |
* @since 3.6 |
98 |
*/ |
94 |
@Override |
99 |
@Override |
95 |
public void updateButtons() { |
100 |
protected void updateExtraButtons() { |
96 |
if (getCurrentPage() instanceof AbstractRepositorySettingsPage |
101 |
if (getCurrentPage() instanceof AbstractRepositorySettingsPage |
97 |
&& ((AbstractRepositorySettingsPage) getCurrentPage()).needsValidation()) { |
102 |
&& ((AbstractRepositorySettingsPage) getCurrentPage()).needsValidation()) { |
98 |
|
103 |
|
Lines 105-174
Link Here
|
105 |
validateServerButton.setVisible(false); |
110 |
validateServerButton.setVisible(false); |
106 |
} |
111 |
} |
107 |
} |
112 |
} |
108 |
super.updateButtons(); |
|
|
109 |
} |
113 |
} |
110 |
|
114 |
|
111 |
/** |
115 |
/** |
112 |
* Overridden so we can react to the validate button being pressed. This could have been done with a straight |
116 |
* @since 3.6 |
113 |
* selection listener in the creation method above, but this is more consistent with how the other buttons work in |
|
|
114 |
* the wizard dialog. |
115 |
* |
116 |
* @since 3.1 |
117 |
*/ |
117 |
*/ |
118 |
@Override |
118 |
@Override |
119 |
protected void buttonPressed(int buttonId) { |
119 |
protected boolean handleExtraButtonPressed(int buttonId) { |
120 |
if (buttonId == VALIDATE_BUTTON_ID) { |
120 |
if (buttonId == VALIDATE_BUTTON_ID) { |
121 |
if (getCurrentPage() instanceof AbstractRepositorySettingsPage) { |
121 |
if (getCurrentPage() instanceof AbstractRepositorySettingsPage) { |
122 |
((AbstractRepositorySettingsPage) getCurrentPage()).validateSettings(); |
122 |
((AbstractRepositorySettingsPage) getCurrentPage()).validateSettings(); |
123 |
} |
123 |
return true; |
124 |
} else { |
|
|
125 |
super.buttonPressed(buttonId); |
126 |
} |
127 |
} |
128 |
|
129 |
/** |
130 |
* Overridden to be able to set proper state for our validate button |
131 |
*/ |
132 |
@Override |
133 |
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, |
134 |
InterruptedException { |
135 |
|
136 |
HashMap<String, Boolean> savedEnabledState = null; |
137 |
try { |
138 |
savedEnabledState = saveAndSetEnabledStateMylyn(); |
139 |
super.run(fork, cancelable, runnable); |
140 |
} finally { |
141 |
if (savedEnabledState != null) { |
142 |
restoreEnabledStateMylyn(savedEnabledState); |
143 |
} |
144 |
} |
145 |
} |
146 |
|
147 |
/** |
148 |
* Modeled after super.saveAndSetEnabledState(), but that one is private, so create our own |
149 |
*/ |
150 |
private HashMap<String, Boolean> saveAndSetEnabledStateMylyn() { |
151 |
HashMap<String, Boolean> savedEnabledState = null; |
152 |
if (getShell() != null) { |
153 |
savedEnabledState = new HashMap<String, Boolean>(); |
154 |
if (validateServerButton != null && validateServerButton.getShell() == getShell()) { |
155 |
savedEnabledState.put(VALIDATE_BUTTON_KEY, validateServerButton.getEnabled()); |
156 |
validateServerButton.setEnabled(false); |
157 |
} |
158 |
} |
159 |
return savedEnabledState; |
160 |
} |
161 |
|
162 |
/** |
163 |
* Modeled after super.restoreEnabledState() and super.restoreUIState() -- couldn't override those since they are |
164 |
* private, so create our own. Currently only single button to work with, so don't create two separate methods |
165 |
*/ |
166 |
private void restoreEnabledStateMylyn(HashMap<String, Boolean> savedEnabledState) { |
167 |
if (savedEnabledState != null) { |
168 |
Boolean savedValidateEnabledState = savedEnabledState.get(VALIDATE_BUTTON_KEY); |
169 |
if (validateServerButton != null && savedValidateEnabledState != null) { |
170 |
validateServerButton.setEnabled(savedValidateEnabledState); |
171 |
} |
124 |
} |
172 |
} |
125 |
} |
|
|
126 |
return false; |
173 |
} |
127 |
} |
174 |
} |
128 |
} |