1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.eclipse.papyrus.dev.project.management.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.dev.project.management.dialog.InputDialogWithCheckBox;
import org.eclipse.swt.widgets.Display;
public abstract class AbstractChangeProjectVersionHandler extends AbstractHandler {
private static final String TITLE = "Enter the new version number for Papyrus plugin.";
private static final String MESSAGE = "Enter the new version number.";
private static final String INITIAL_VALUE = "0.0.0.qualifier";
private static final String CHECKBOX_MESSAGE = "Only projects beginning with 'org.eclipse.papyrus.*'";
private static final String WARNING_DIALOG_TITLE = "Change Version Name Report";
private static final String WARNING_DIALOG_MESSAGE = "The following project were NOT managed : ";
private static final String WARNING_DIALOG_MESSAGE2 = "Done.";
private static final String PAPYRUS_NAME = "org.eclipse.papyrus";
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IInputValidator validator = new IInputValidator() {
public String isValid(final String newText) {
final boolean match = newText.matches("[0-9]+\\.[0-9]+\\.[0-9]+\\.qualifier");
if(!match) {
return NLS.bind("The version number should be : something like this : {0}.", INITIAL_VALUE);
}
return null;
}
};
final InputDialogWithCheckBox dialog = new InputDialogWithCheckBox(Display.getCurrent().getActiveShell(), TITLE, MESSAGE, INITIAL_VALUE, CHECKBOX_MESSAGE, true, validator);
if(dialog.open() == Window.OK) {
Job job = new Job("Update version numbers") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus result = runAsJob(dialog.getValue(), dialog.isChecked(), monitor);
return result;
}
};
job.setUser(true);
job.schedule();
}
return null;
}
protected IStatus runAsJob(final String newVersion, final boolean papyrusProjectsOnly, IProgressMonitor monitor) {
String notManagedProjectNames = "";
final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
monitor.beginTask("Update version numbers", projects.length);
for(final IProject current : projects) {
final String name = current.getName();
if(papyrusProjectsOnly) {
if(name.startsWith(PAPYRUS_NAME)) {//we test the project name
setVersionNumber(current, newVersion, notManagedProjectNames);
} else {
notManagedProjectNames += NLS.bind("- {0} \n", current.getName());
}
} else {
setVersionNumber(current, newVersion, notManagedProjectNames);
}
monitor.worked(1);
}
//FIXME: We're not in the UI Thread anymore. We can't open a Dialog.
if(notManagedProjectNames.equals("")) {
final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE2, MessageDialog.INFORMATION, new String[]{ "OK" }, 0);
informationDialog.open();
} else {
final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE + "\n" + notManagedProjectNames, MessageDialog.INFORMATION, new String[]{ "OK" }, 0);
informationDialog.open();
}
return Status.OK_STATUS;
}
/**
*
* @param project
* the project to manage
* @param newVersion
* the new version for the project
* @param notManagedProjectNames
* a String used to build the message with the not managed projects
*/
protected abstract void setVersionNumber(final IProject project, final String newVersion, String notManagedProjectNames);
}
|