View | Details | Raw Unified | Return to bug 201998 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java (-7 / +29 lines)
Lines 12-17 Link Here
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Iterator;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
Lines 37-44 Link Here
37
	private ModelChangeTable fModelChangeTable;
38
	private ModelChangeTable fModelChangeTable;
38
	private boolean fCanceled;
39
	private boolean fCanceled;
39
40
40
	public GetNonExternalizedStringsOperation(ISelection selection) {
41
	//Azure: To indicate that only selected plug-ins under <code>fSelection</code> are to be externalized.
42
	private boolean fExternalizeSelectedPluginsOnly;
43
44
	public GetNonExternalizedStringsOperation(ISelection selection, boolean externalizeSelectedPluginsOnly) {
41
		fSelection = selection;
45
		fSelection = selection;
46
		fExternalizeSelectedPluginsOnly = externalizeSelectedPluginsOnly;
42
	}
47
	}
43
48
44
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
49
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Lines 56-67 Link Here
56
61
57
			fModelChangeTable = new ModelChangeTable();
62
			fModelChangeTable = new ModelChangeTable();
58
63
59
			IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels();
64
			/*
60
			monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length);
65
			 * Azure: This will add only the preselected plug-ins to the ModelChangeTable
61
			for (int i = 0; i < pluginModels.length && !fCanceled; i++) {
66
			 * instead of adding the list of all plug-ins in the workspace. This is useful
62
				IProject project = pluginModels[i].getUnderlyingResource().getProject();
67
			 * when the Internationalize action is run on a set of non-externalized plug-ins
63
				if (!WorkspaceModelManager.isBinaryProject(project))
68
			 * where there is no need to display all non-externalized plug-ins in the
64
					getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1));
69
			 * workspace, but only those selected.
70
			 */
71
			if (fExternalizeSelectedPluginsOnly) {
72
				monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, fSelectedModels.size());
73
				Iterator iterator = fSelectedModels.iterator();
74
				while (iterator.hasNext() && !fCanceled) {
75
					IProject project = (IProject) iterator.next();
76
					if (!WorkspaceModelManager.isBinaryProject(project))
77
						getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1));
78
				}
79
			} else {
80
				IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels();
81
				monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length);
82
				for (int i = 0; i < pluginModels.length && !fCanceled; i++) {
83
					IProject project = pluginModels[i].getUnderlyingResource().getProject();
84
					if (!WorkspaceModelManager.isBinaryProject(project))
85
						getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1));
86
				}
65
			}
87
			}
66
		}
88
		}
67
	}
89
	}
(-)src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java (-3 / +52 lines)
Lines 23-34 Link Here
23
public class GetNonExternalizedStringsAction implements IWorkbenchWindowActionDelegate {
23
public class GetNonExternalizedStringsAction implements IWorkbenchWindowActionDelegate {
24
24
25
	private ISelection fSelection;
25
	private ISelection fSelection;
26
	//Azure: To indicate that only selected plug-ins are to be externalized. False by default.
27
	private boolean fExternalizeSelectedPluginsOnly = false;
28
29
	//Azure: To indicate that the post-externalization message dialog should not be displayed.
30
	private boolean fSkipMessageDialog = false;
26
31
27
	public GetNonExternalizedStringsAction() {
32
	public GetNonExternalizedStringsAction() {
28
	}
33
	}
29
34
30
	public void run(IAction action) {
35
	public void run(IAction action) {
31
		GetNonExternalizedStringsOperation runnable = new GetNonExternalizedStringsOperation(fSelection);
36
		/* 
37
		 * Azure: Pass <code>fExternalizeSelectedPluginsOnly</code> to the operation to indicate
38
		 * that only the plug-ins passed in the selection are to be externalized and such that
39
		 * only those are displayed on the change table in the ExternalizeStringsWizard.
40
		 */
41
		GetNonExternalizedStringsOperation runnable = new GetNonExternalizedStringsOperation(fSelection, fExternalizeSelectedPluginsOnly);
32
		try {
42
		try {
33
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
43
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
34
		} catch (InvocationTargetException e) {
44
		} catch (InvocationTargetException e) {
Lines 47-54 Link Here
47
					op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$
57
					op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$
48
				} catch (final InterruptedException irex) {
58
				} catch (final InterruptedException irex) {
49
				}
59
				}
50
			} else
60
			} else {
51
				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedMessage);
61
				/* 
62
				 * Azure: When the InternationalizeAction invokes the ExternalizeStringsAction,
63
				 * <code>fSkipMessageDialog</code> is set to true in order for no intermediate
64
				 * message to appear if all selected plug-ins were already externalized.
65
				 */
66
				if (!fSkipMessageDialog)
67
					MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedMessage);
68
			}
52
		}
69
		}
53
	}
70
	}
54
71
Lines 61-64 Link Here
61
78
62
	public void init(IWorkbenchWindow window) {
79
	public void init(IWorkbenchWindow window) {
63
	}
80
	}
81
82
	/**
83
	 * TODO: Azure Documentation
84
	 * @param externalizeSelectedPluginsOnly
85
	 */
86
	public void setExternalizeSelectedPluginsOnly(boolean externalizeSelectedPluginsOnly) {
87
		fExternalizeSelectedPluginsOnly = externalizeSelectedPluginsOnly;
88
	}
89
90
	/**
91
	 * TODO: Azure Documentation
92
	 * @return
93
	 */
94
	public boolean isExternalizeSelectedPluginsOnly() {
95
		return fExternalizeSelectedPluginsOnly;
96
	}
97
98
	/**
99
	 * TODO: Azure Documentation
100
	 * @param skipMessageDialog
101
	 */
102
	public void setSkipMessageDialog(boolean skipMessageDialog) {
103
		this.fSkipMessageDialog = skipMessageDialog;
104
	}
105
106
	/**
107
	 * TODO: Azure Documentation
108
	 * @return
109
	 */
110
	public boolean isSkipMessageDialog() {
111
		return fSkipMessageDialog;
112
	}
64
}
113
}
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+20 lines)
Lines 2454-2459 Link Here
2454
2454
2455
	public static String ExternalizeStringsWizardPage_keySuggested;
2455
	public static String ExternalizeStringsWizardPage_keySuggested;
2456
2456
2457
	public static String InternationalizeAction_internationalizeTitle;
2458
2459
	public static String InternationalizeAction_internationalizeMessage;
2460
2461
	public static String InternationalizeWizard_title;
2462
2463
	public static String InternationalizeWizard_PluginPage_internationalizeList;
2464
2465
	public static String InternationalizeWizard_PluginPage_availableList;
2466
2467
	public static String InternationalizeWizard_PluginPage_filter;
2468
2469
	public static String InternationalizeWizard_PluginPage_pageTitle;
2470
2471
	public static String InternationalizeWizard_PluginPage_pageDescription;
2472
2473
	public static String InternationalizeWizard_LocalePage_pageTitle;
2474
2475
	public static String InternationalizeWizard_LocalePage_pageDescription;
2476
2457
	public static String NewProjectCreationPage_target;
2477
	public static String NewProjectCreationPage_target;
2458
2478
2459
	public static String NewProjectCreationPage_ftarget;
2479
	public static String NewProjectCreationPage_ftarget;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+11 lines)
Lines 2026-2031 Link Here
2026
IntroSection_sectionDescription=The welcome page appears the first time the product is launched.  It is intended to introduce the features of the product to new users.
2026
IntroSection_sectionDescription=The welcome page appears the first time the product is launched.  It is intended to introduce the features of the product to new users.
2027
IntroSection_undefinedProductId=Undefined Product ID
2027
IntroSection_undefinedProductId=Undefined Product ID
2028
2028
2029
InternationalizeAction_internationalizeTitle=Internationalize Plug-ins
2030
InternationalizeAction_internationalizeMessage=All plug-ins have been internationalized
2031
InternationalizeWizard_title=Internationalize Plug-ins
2032
InternationalizeWizard_PluginPage_internationalizeList = P&lug-ins to Internationlize:
2033
InternationalizeWizard_PluginPage_availableList = P&lug-ins found:
2034
InternationalizeWizard_PluginPage_filter = Filter Available Plug-ins
2035
InternationalizeWizard_PluginPage_pageTitle=Internationalize Plug-ins
2036
InternationalizeWizard_PluginPage_pageDescription=Select the plug-ins to be internationalized.
2037
InternationalizeWizard_LocalePage_pageTitle=Internationalize Plug-ins
2038
InternationalizeWizard_LocalePage_pageDescription=Select the locales for which plug-ins should be internationalized.
2039
2029
2040
2030
MainTab_jreSection = Java Runtime Environment
2041
MainTab_jreSection = Java Runtime Environment
2031
EquinoxLaunchConfiguration_oldTarget=The org.eclipse.osgi plug-in is missing from this configuration.
2042
EquinoxLaunchConfiguration_oldTarget=The org.eclipse.osgi plug-in is missing from this configuration.
(-)plugin.properties (-1 / +3 lines)
Lines 248-251 Link Here
248
248
249
pluginsearch.action.name = Open Plug-in Artifact
249
pluginsearch.action.name = Open Plug-in Artifact
250
pluginsearch.action.menu.name = Open &Plug-in Artifact...		
250
pluginsearch.action.menu.name = Open &Plug-in Artifact...		
251
pluginsearch.action.desc = Open a plug-in artifact in the manifest editor
251
pluginsearch.action.desc = Open a plug-in artifact in the manifest editor
252
253
Internationalize.label = Internationalize...
(-)plugin.xml (-1 / +22 lines)
Lines 587-592 Link Here
587
               id="org.eclipse.pde.ui.ExternalizeStrings">
587
               id="org.eclipse.pde.ui.ExternalizeStrings">
588
         </action>
588
         </action>
589
         <action
589
         <action
590
			   label="%Internationalize.label"
591
			   class="org.eclipse.pde.internal.ui.nls.InternationalizeAction"
592
			   menubarPath="org.eclipse.pde.ui.plugin.tools/group0"
593
               enablesFor="+"
594
               id="org.eclipse.pde.ui.Internationalize">
595
         </action>
596
         <action
590
               label="%OrganizeManifest.label"
597
               label="%OrganizeManifest.label"
591
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
598
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
592
               class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction"
599
               class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction"
Lines 625-631 Link Here
625
               menubarPath="org.eclipse.pde.ui.manifest.tools/group0"
632
               menubarPath="org.eclipse.pde.ui.manifest.tools/group0"
626
               enablesFor="+"
633
               enablesFor="+"
627
               id="org.eclipse.pde.ui.ExternalizeStrings">
634
               id="org.eclipse.pde.ui.ExternalizeStrings">
628
         </action> 
635
         </action>
636
         <action
637
			   label="%Internationalize.label"
638
			   class="org.eclipse.pde.internal.ui.nls.InternationalizeAction"
639
			   menubarPath="org.eclipse.pde.ui.manifest.tools/group0"
640
               enablesFor="+"
641
               id="org.eclipse.pde.ui.Internationalize">
642
         </action>
629
         <action
643
         <action
630
               label="%OrganizeManifest.label"
644
               label="%OrganizeManifest.label"
631
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
645
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
Lines 853-858 Link Here
853
               id="org.eclipse.pde.ui.ExternalizeStrings">
867
               id="org.eclipse.pde.ui.ExternalizeStrings">
854
         </action>
868
         </action>
855
         <action
869
         <action
870
			   label="%Internationalize.label"
871
			   class="org.eclipse.pde.internal.ui.nls.InternationalizeAction"
872
			   menubarPath="org.eclipse.pde.ui.project.tools/group1"
873
               enablesFor="+"
874
               id="org.eclipse.pde.ui.Internationalize">
875
         </action>
876
         <action
856
               label="%OrganizeManifest.label"
877
               label="%OrganizeManifest.label"
857
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
878
               helpContextId="org.eclipse.pde.doc.user.organize_manifest"
858
               class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction"
879
               class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction"
(-)src/org/eclipse/pde/internal/ui/nls/NLSFragmentsGenerator.java (+200 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.lang.reflect.InvocationTargetException;
4
import java.util.List;
5
import java.util.Locale;
6
import org.eclipse.core.resources.*;
7
import org.eclipse.core.runtime.*;
8
import org.eclipse.jface.wizard.IWizardContainer;
9
import org.eclipse.pde.core.plugin.IPluginModelBase;
10
import org.eclipse.pde.internal.core.TargetPlatformHelper;
11
import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase;
12
import org.eclipse.pde.internal.ui.PDEPlugin;
13
import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
14
import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
15
import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard.ImportQuery;
16
import org.eclipse.pde.internal.ui.wizards.plugin.FragmentFieldData;
17
import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationOperation;
18
import org.eclipse.swt.widgets.Shell;
19
20
public class NLSFragmentsGenerator {
21
22
	private List pluginsToBeInternationalized;
23
	//private List requiredLocales;
24
25
	private static final String PERIOD = "."; //$NON-NLS-1$
26
	private static final String MIN_MINOR = "0"; //$NON-NLS-1$
27
	private static final String MAX_MINOR = "9"; //$NON-NLS-1$
28
	private static final String NL_FRAGMENT_EXTENSION = ".nl1"; //$NON-NLS-1$
29
	private static final String LEFT_SQUARE_BRACKET = "["; //$NON-NLS-1$
30
	private static final String RIGHT_PARENTHESIS = ")"; //$NON-NLS-1$
31
	private static final String DEFAULT_VERSION = "1.0.0"; //$NON-NLS-1$
32
	private static final String VERSION_FORMAT_WITH_QUALIFIER = "\\d+\\.\\d+\\.\\d+\\..+"; //$NON-NLS-1$
33
	private static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$
34
	private static final String PROPERTIES_FILE_PREFIX = "plugin_"; //$NON-NLS-1$
35
36
	private FragmentFieldData fFragmentData;
37
	private IProjectProvider fProjectProvider;
38
	private IPluginModelBase currentPlugin;
39
	private IWizardContainer container;
40
	private IProject currentPluginProject;
41
42
	public NLSFragmentsGenerator(List plugins, List locales, IWizardContainer container) {
43
		this.pluginsToBeInternationalized = plugins;
44
		//this.requiredLocales = locales;
45
		this.container = container;
46
47
		internationalizePlugins();
48
	}
49
50
	private void internationalizePlugins() {
51
		for (Object pluginObject : pluginsToBeInternationalized) {
52
			IPluginModelBase plugin = (IPluginModelBase) pluginObject;
53
			createNLFragment(plugin);
54
55
			if (currentPlugin instanceof ExternalPluginModelBase) {
56
				doImportOperation(container.getShell(), PluginImportOperation.IMPORT_WITH_SOURCE, currentPlugin, true);
57
			}
58
59
			IProject currentFragmentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION);
60
			createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.FRENCH);
61
			createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.ENGLISH);
62
			createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.CHINA);
63
64
			if (currentPlugin instanceof ExternalPluginModelBase) { 
65
				try {
66
					currentPluginProject.delete(true, true, new NullProgressMonitor());
67
				} catch (CoreException c) {
68
					System.out.println(c);
69
				}
70
			}
71
		}
72
	}
73
74
	private void createNLFragment(IPluginModelBase plugin) {
75
		fFragmentData = new FragmentFieldData();
76
77
		currentPlugin = plugin;
78
		currentPluginProject = ResourcesPlugin.getWorkspace().getRoot().getProject(currentPlugin.getPluginBase().getId());
79
80
		populateFieldData();
81
82
		fProjectProvider = new IProjectProvider() {
83
			public String getProjectName() {
84
				return currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION;
85
			}
86
87
			public IProject getProject() {
88
				return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
89
			}
90
91
			public IPath getLocationPath() {
92
				return new Path(Platform.getLocation().toOSString());
93
			}
94
		};
95
96
		try {
97
			container.run(false, true, new NewProjectCreationOperation(fFragmentData, fProjectProvider, null));
98
		} catch (InvocationTargetException e) {
99
			PDEPlugin.logException(e);
100
		} catch (InterruptedException e) {
101
		}
102
	}
103
104
	private void populateFieldData() {
105
106
		fFragmentData.setId(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION);
107
		fFragmentData.setVersion(DEFAULT_VERSION);
108
		fFragmentData.setMatch(0);
109
110
		fFragmentData.setPluginId(currentPlugin.getPluginBase().getId());
111
		fFragmentData.setPluginVersion(incrementRelease(currentPlugin.getPluginBase().getVersion()));
112
		fFragmentData.setName(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION + " Fragment"); //$NON-NLS-1$
113
		fFragmentData.setProvider(""); //$NON-NLS-1$
114
		fFragmentData.setSimple(true);
115
116
		if (!(currentPlugin instanceof ExternalPluginModelBase)) {
117
			fFragmentData.setSourceFolderName("src"); //$NON-NLS-1$
118
			fFragmentData.setOutputFolderName("bin"); //$NON-NLS-1$
119
		}
120
121
		fFragmentData.setLegacy(false);
122
		fFragmentData.setTargetVersion(Double.toString(ensureTargetVersionCompatibility(TargetPlatformHelper.getTargetVersion())));
123
		fFragmentData.setHasBundleStructure(true);
124
		fFragmentData.setOSGiFramework(null);
125
		fFragmentData.setWorkingSets(null);
126
	}
127
128
	private String incrementRelease(String oldVersion) {
129
130
		if (oldVersion.matches(VERSION_FORMAT_WITH_QUALIFIER)) {
131
			oldVersion = oldVersion.substring(0, oldVersion.lastIndexOf(PERIOD));
132
		}
133
134
		String newVersion = LEFT_SQUARE_BRACKET + oldVersion + ',';
135
		String oldMinor = oldVersion.substring(oldVersion.indexOf(PERIOD) + 1, oldVersion.lastIndexOf(PERIOD));
136
		String oldMicro = oldVersion.substring(oldVersion.lastIndexOf(PERIOD) + 1);
137
138
		if (oldMinor.compareTo(MAX_MINOR) == 0) {
139
			String major = Integer.toString(Integer.valueOf(oldVersion.substring(0, oldVersion.indexOf(PERIOD))) + 1);
140
			newVersion += major + PERIOD + MIN_MINOR + PERIOD + oldMicro + RIGHT_PARENTHESIS;
141
		} else {
142
			String major = oldVersion.substring(0, oldVersion.indexOf(PERIOD));
143
			String newMinor = Integer.toString(Integer.valueOf(oldMinor) + 1);
144
			newVersion += major + PERIOD + newMinor + PERIOD + oldMicro + RIGHT_PARENTHESIS;
145
		}
146
147
		return newVersion;
148
	}
149
150
	private void createLocaleSpecificPropertiesFile(IProject fragmentProject, Locale locale) {
151
152
		IFile pluginProperties;
153
154
		if (currentPlugin instanceof ExternalPluginModelBase) {
155
			pluginProperties = currentPluginProject.getFile("plugin.properties"); //$NON-NLS-1$
156
		} else {
157
			pluginProperties = currentPlugin.getUnderlyingResource().getProject().getFile("plugin.properties"); //$NON-NLS-1$
158
		}
159
160
		IFile localeProperties = fragmentProject.getFile(PROPERTIES_FILE_PREFIX + locale.getLanguage() + PROPERTIES_FILE_EXTENSION);
161
162
		if (!localeProperties.exists()) {
163
			try {
164
				pluginProperties.copy(localeProperties.getFullPath(), false, null);
165
166
			} catch (Exception e) {
167
				System.out.println(e);
168
			}
169
		}
170
	}
171
172
	private double ensureTargetVersionCompatibility(double targetVersion) {
173
		if (targetVersion < 3.0) {
174
			return 3.4;
175
		}
176
		return targetVersion;
177
	}
178
179
	public static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase model, final boolean forceAutobuild) {
180
		doImportOperation(shell, importType, new IPluginModelBase[] {model}, forceAutobuild);
181
	}
182
183
	public static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase[] models, final boolean forceAutobuild) {
184
		doImportOperation(shell, importType, models, forceAutobuild, false);
185
	}
186
187
	private static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase[] models, final boolean forceAutobuild, final boolean launchedConfiguration) {
188
		PluginImportOperation.IImportQuery query = new ImportQuery(shell);
189
		PluginImportOperation.IImportQuery executionQuery = new ImportQuery(shell);
190
		final PluginImportOperation op = new PluginImportOperation(models, importType, query, executionQuery, forceAutobuild);
191
		op.setLaunchedConfiguration(launchedConfiguration);
192
193
		try {
194
			PDEPlugin.getWorkspace().run(op, new NullProgressMonitor());
195
		} catch (CoreException e) {
196
			PDEPlugin.logException(e);
197
		}
198
199
	}
200
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardOpenOperation.java (+64 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import org.eclipse.core.resources.ResourcesPlugin;
4
import org.eclipse.core.runtime.Assert;
5
import org.eclipse.core.runtime.OperationCanceledException;
6
import org.eclipse.core.runtime.jobs.IJobManager;
7
import org.eclipse.core.runtime.jobs.Job;
8
import org.eclipse.jface.dialogs.Dialog;
9
import org.eclipse.jface.window.Window;
10
import org.eclipse.jface.wizard.IWizardContainer;
11
import org.eclipse.jface.wizard.WizardDialog;
12
import org.eclipse.swt.custom.BusyIndicator;
13
import org.eclipse.swt.widgets.Shell;
14
15
/**
16
 * A helper class to open an InternationalizeWizard dialog.
17
 * 
18
 * @author Team Azure
19
 */
20
public class InternationalizeWizardOpenOperation {
21
22
	private InternationalizeWizard fWizard;
23
24
	public InternationalizeWizardOpenOperation(InternationalizeWizard wizard) {
25
		Assert.isNotNull(wizard);
26
		fWizard = wizard;
27
	}
28
29
	public int run(final Shell parent, final String dialogTitle) throws InterruptedException {
30
		Assert.isNotNull(dialogTitle);
31
		final IJobManager manager = Job.getJobManager();
32
		final int[] result = new int[1];
33
		final InterruptedException[] canceled = new InterruptedException[1];
34
35
		Runnable r = new Runnable() {
36
			public void run() {
37
				try {
38
					manager.beginRule(ResourcesPlugin.getWorkspace().getRoot(), null);
39
40
					Dialog dialog = new WizardDialog(parent, fWizard);
41
					dialog.create();
42
43
					IWizardContainer wizardContainer = (IWizardContainer) dialog;
44
					if (wizardContainer.getCurrentPage() == null) {
45
						//Close the dialog if there are no pages
46
						result[0] = Window.CANCEL;
47
					} else {
48
						//Open the wizard dialog
49
						result[0] = dialog.open();
50
					}
51
52
				} catch (OperationCanceledException e) {
53
					canceled[0] = new InterruptedException(e.getMessage());
54
				} finally {
55
					manager.endRule(ResourcesPlugin.getWorkspace().getRoot());
56
				}
57
			}
58
		};
59
		BusyIndicator.showWhile(parent.getDisplay(), r);
60
		if (canceled[0] != null)
61
			throw canceled[0];
62
		return result[0];
63
	}
64
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeAction.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.nls;
12
13
import java.lang.reflect.InvocationTargetException;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.pde.internal.ui.PDEPlugin;
19
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.ui.*;
21
22
/**
23
 * This action class is responsible for creating and initializing the
24
 * InternationalizeWizard.
25
 * 
26
 * @author Team Azure
27
 *
28
 */
29
public class InternationalizeAction implements IWorkbenchWindowActionDelegate {
30
31
	private IStructuredSelection fSelection;
32
33
	public InternationalizeAction() {
34
	}
35
36
	public void run(IAction action) {
37
		//Create an InternationalizeOperation on the workbench selection.
38
		InternationalizeOperation runnable = new InternationalizeOperation(fSelection);
39
		try {
40
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
41
		} catch (InvocationTargetException e) {
42
		} catch (InterruptedException e) {
43
		} finally {
44
			if (runnable.wasCanceled()) {
45
				return;
46
			}
47
48
			/*	Get the plugin model table containing the list of workspace and 
49
			 * 	external plug-ins
50
			 */
51
			InternationalizeModelTable pluginTable = runnable.getPluginTable();
52
53
			if (!pluginTable.isEmpty()) {
54
55
				InternationalizeWizard wizard = new InternationalizeWizard(action, pluginTable);
56
				wizard.init(PlatformUI.getWorkbench(), fSelection);
57
58
				//Create an operation to start and run the wizard
59
				InternationalizeWizardOpenOperation op = new InternationalizeWizardOpenOperation(wizard);
60
				try {
61
					op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$
62
				} catch (final InterruptedException irex) {
63
				}
64
			} else {
65
				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.InternationalizeAction_internationalizeTitle, PDEUIMessages.InternationalizeAction_internationalizeMessage);
66
			}
67
		}
68
	}
69
70
	public void selectionChanged(IAction action, ISelection selection) {
71
		fSelection = (IStructuredSelection) selection;
72
	}
73
74
	public void dispose() {
75
	}
76
77
	public void init(IWorkbenchWindow window) {
78
	}
79
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardLocalePage.java (+572 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.ui.nls;
5
6
import java.util.*;
7
import java.util.List;
8
import java.util.regex.Pattern;
9
import org.eclipse.core.runtime.*;
10
import org.eclipse.jface.dialogs.Dialog;
11
import org.eclipse.jface.dialogs.IDialogSettings;
12
import org.eclipse.jface.layout.GridLayoutFactory;
13
import org.eclipse.jface.viewers.*;
14
import org.eclipse.jface.wizard.IWizardContainer;
15
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.pde.core.IModelProviderEvent;
18
import org.eclipse.pde.core.IModelProviderListener;
19
import org.eclipse.pde.internal.core.PDECore;
20
import org.eclipse.pde.internal.core.util.PatternConstructor;
21
import org.eclipse.pde.internal.ui.*;
22
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
23
import org.eclipse.pde.internal.ui.util.SWTUtil;
24
import org.eclipse.pde.internal.ui.wizards.ListUtil;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.custom.ScrolledComposite;
27
import org.eclipse.swt.events.*;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.*;
31
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.progress.WorkbenchJob;
33
34
/**
35
 * @author Robbie
36
 *
37
 */
38
public class InternationalizeWizardLocalePage extends WizardPage implements IModelProviderListener {
39
40
	public static final String PAGE_NAME = "InternationalizeWizardLocalePage"; //$NON-NLS-1$
41
42
	protected Locale[] fModels = new Locale[0];
43
	private String fLocation;
44
45
	protected TableViewer fSelectedListViewer;
46
	private boolean fRefreshNeeded = true;
47
48
	private Label fCountLabel;
49
	private TableViewer fAvailableListViewer;
50
51
	// this job is used to delay the full filter refresh for 200 milliseconds in case the user is still typing
52
	private WorkbenchJob fFilterJob;
53
	private Text fFilterText;
54
	private AvailableFilter fFilter;
55
56
	// fSelected is used to track the selection in a HashMap so we can efficiently
57
	// filter selected items out of the available item list
58
	private HashMap fSelected;
59
	// used to block the selection listeners from updating button enablement when programatically removing items
60
	private boolean fBlockSelectionListeners;
61
	private Button fAddButton;
62
	private Button fAddAllButton;
63
	private Button fRemoveButton;
64
	private Button fRemoveAllButton;
65
66
	private InternationalizeModelTable fInternationalizeModelTable;
67
68
	private class AvailableFilter extends ViewerFilter {
69
		private Pattern fPattern;
70
71
		public AvailableFilter() {
72
			setPattern("*"); //$NON-NLS-1$
73
		}
74
75
		public boolean select(Viewer viewer, Object parentElement, Object element) {
76
			// filter out any items that are currently selected
77
			// on a full refresh, these will have been added back to the list
78
			if (fSelected.containsKey(element))
79
				return false;
80
			if (!(element instanceof Locale))
81
				return false;
82
			String localeName = ((Locale) element).toString();
83
			if (fPattern.matcher(localeName).matches())
84
				return true;
85
			return false;
86
		}
87
88
		public boolean setPattern(String newPattern) {
89
			if (!newPattern.endsWith("*")) //$NON-NLS-1$
90
				newPattern += "*"; //$NON-NLS-1$
91
			if (!newPattern.startsWith("*")) //$NON-NLS-1$
92
				newPattern = "*" + newPattern; //$NON-NLS-1$
93
			if (fPattern != null) {
94
				String oldPattern = fPattern.pattern();
95
				if (newPattern.equals(oldPattern))
96
					return false;
97
			}
98
			fPattern = PatternConstructor.createPattern(newPattern, true);
99
			return true;
100
		}
101
	}
102
103
	/*private String[] getLocales() {
104
		Locale[] locales = Locale.getAvailableLocales();
105
		String[] result = new String[locales.length];
106
		for (int i = 0; i < locales.length; i++) {
107
			Locale locale = locales[i];
108
			StringBuffer buffer = new StringBuffer();
109
			buffer.append(locale.toString());
110
			buffer.append(" - "); //$NON-NLS-1$
111
			buffer.append(locale.getDisplayName());
112
			result[i] = buffer.toString();
113
		}
114
		return result;
115
	}*/
116
117
	private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
118
		public Object[] getElements(Object parent) {
119
			return fInternationalizeModelTable.getModels();
120
		}
121
	}
122
123
	private class SelectedContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
124
		public Object[] getElements(Object parent) {
125
			return null;
126
		}
127
	}
128
129
	public InternationalizeWizardLocalePage(InternationalizeModelTable modelTable, String pageName) {
130
		super(pageName);
131
		PDEPlugin.getDefault().getLabelProvider().connect(this);
132
		PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this);
133
134
		fInternationalizeModelTable = modelTable;
135
		fSelected = new HashMap();
136
137
		IWizardContainer container = getContainer();
138
		if (container != null)
139
			container.updateButtons();
140
	}
141
142
	private void addFilter() {
143
		fFilter = new AvailableFilter();
144
		fAvailableListViewer.addFilter(fFilter);
145
		fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$
146
			public IStatus runInUIThread(IProgressMonitor monitor) {
147
				handleFilter();
148
				return Status.OK_STATUS;
149
			}
150
		};
151
		fFilterJob.setSystem(true);
152
	}
153
154
	private void handleFilter() {
155
		boolean changed = false;
156
		String newFilter;
157
		if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0)
158
			newFilter = "*"; //$NON-NLS-1$
159
		changed = fFilter.setPattern(newFilter);
160
		if (changed) {
161
			fAvailableListViewer.getTable().setRedraw(false);
162
			fAvailableListViewer.refresh();
163
			fAvailableListViewer.getTable().setRedraw(true);
164
			updateButtonEnablement(false, false);
165
		}
166
	}
167
168
	/* (non-Javadoc)
169
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
170
	 */
171
	public void createControl(Composite parent) {
172
		Composite container = new Composite(parent, SWT.NONE);
173
		GridLayout layout = new GridLayout();
174
		layout.numColumns = 3;
175
		layout.makeColumnsEqualWidth = false;
176
		layout.horizontalSpacing = 5;
177
		layout.verticalSpacing = 10;
178
		container.setLayout(layout);
179
180
		createScrollArea(container);
181
		createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
182
		createButtonArea(container);
183
		createLocaleList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
184
		updateCount();
185
186
		// create container for buttons
187
		Composite buttonContainer = new Composite(container, SWT.NONE);
188
		buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create());
189
190
		addViewerListeners();
191
		addFilter();
192
193
		initialize();
194
		setControl(container);
195
		Dialog.applyDialogFont(container);
196
		PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE);
197
	}
198
199
	protected Composite createLocaleList(Composite parent) {
200
		Composite container = new Composite(parent, SWT.NONE);
201
		GridLayout layout = new GridLayout();
202
		layout.marginWidth = 0;
203
		layout.marginHeight = 0;
204
		container.setLayout(layout);
205
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
206
207
		Label label = new Label(container, SWT.NONE);
208
		label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_internationalizeList);
209
210
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
211
		GridData gd = new GridData(GridData.FILL_BOTH);
212
		gd.widthHint = 225;
213
		table.setLayoutData(gd);
214
215
		fSelectedListViewer = new TableViewer(table);
216
		fSelectedListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
217
		fSelectedListViewer.setContentProvider(new SelectedContentProvider());
218
		//fSelectedListViewer.setInput(); TODO Pass proper input to TableViewer
219
		fSelectedListViewer.setComparator(ListUtil.NAME_COMPARATOR);
220
		return container;
221
	}
222
223
	protected boolean isRefreshNeeded() {
224
		if (fRefreshNeeded) {
225
			fRefreshNeeded = false;
226
			return true;
227
		}
228
		if (fLocation == null) {
229
			return true;
230
		}
231
		return false;
232
	}
233
234
	protected void addLocale(Locale model, ArrayList selected) {
235
		if (!selected.contains(model)) {
236
			selected.add(model);
237
		}
238
	}
239
240
	public List getLocalesForInternationalization() {
241
		TableItem[] items = fSelectedListViewer.getTable().getItems();
242
		List result = new ArrayList();
243
		for (int i = 0; i < items.length; i++) {
244
			result.add(items[i].getData());
245
		}
246
		return result;
247
	}
248
249
	public void storeSettings() {
250
		IDialogSettings settings = getDialogSettings();
251
	}
252
253
	/* (non-Javadoc)
254
	 * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent)
255
	 */
256
	public void modelsChanged(IModelProviderEvent event) {
257
		fRefreshNeeded = true;
258
	}
259
260
	private void initialize() {
261
		updateButtonEnablement(true, true);
262
		setPageComplete(false);
263
	}
264
265
	private void addViewerListeners() {
266
		fAvailableListViewer.addDoubleClickListener(new IDoubleClickListener() {
267
			public void doubleClick(DoubleClickEvent event) {
268
				handleAdd();
269
			}
270
		});
271
272
		fSelectedListViewer.addDoubleClickListener(new IDoubleClickListener() {
273
			public void doubleClick(DoubleClickEvent event) {
274
				handleRemove();
275
			}
276
		});
277
278
		fAvailableListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
279
			public void selectionChanged(SelectionChangedEvent event) {
280
				if (!fBlockSelectionListeners)
281
					updateSelectionBasedEnablement(event.getSelection(), true);
282
			}
283
		});
284
285
		fSelectedListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
286
			public void selectionChanged(SelectionChangedEvent event) {
287
				if (!fBlockSelectionListeners)
288
					updateSelectionBasedEnablement(event.getSelection(), false);
289
			}
290
		});
291
292
		fFilterText.addModifyListener(new ModifyListener() {
293
			public void modifyText(ModifyEvent e) {
294
				fFilterJob.cancel();
295
				fFilterJob.schedule(200);
296
			}
297
		});
298
299
	}
300
301
	private Composite createAvailableList(Composite parent) {
302
		Composite container = new Composite(parent, SWT.NONE);
303
		GridLayout layout = new GridLayout();
304
		layout.marginWidth = 0;
305
		layout.marginHeight = 0;
306
		container.setLayout(layout);
307
		container.setLayoutData(new GridData());
308
309
		Label label = new Label(container, SWT.NONE);
310
		label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_availableList);
311
312
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
313
		GridData gd = new GridData(GridData.FILL_BOTH);
314
		gd.heightHint = 200;
315
		gd.widthHint = 225;
316
		table.setLayoutData(gd);
317
318
		fAvailableListViewer = new TableViewer(table);
319
		fAvailableListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
320
		fAvailableListViewer.setContentProvider(new ContentProvider());
321
		//fAvailableListViewer.setInput(); TODO Pass proper input to TableViewer
322
		fAvailableListViewer.setComparator(ListUtil.NAME_COMPARATOR);
323
324
		return container;
325
	}
326
327
	private Composite createButtonArea(Composite parent) {
328
		ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
329
		GridLayout layout = new GridLayout();
330
		layout.marginWidth = layout.marginHeight = 0;
331
		comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
332
		Composite container = new Composite(comp, SWT.NONE);
333
		layout = new GridLayout();
334
		layout.marginWidth = 0;
335
		container.setLayout(layout);
336
		GridData gd = new GridData(GridData.FILL_VERTICAL);
337
		gd.verticalIndent = 15;
338
		container.setLayoutData(gd);
339
340
		fAddButton = new Button(container, SWT.PUSH);
341
		fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add);
342
		fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
343
		fAddButton.addSelectionListener(new SelectionAdapter() {
344
			public void widgetSelected(SelectionEvent e) {
345
				handleAdd();
346
			}
347
		});
348
		SWTUtil.setButtonDimensionHint(fAddButton);
349
350
		fAddAllButton = new Button(container, SWT.PUSH);
351
		fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll);
352
		fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
353
		fAddAllButton.addSelectionListener(new SelectionAdapter() {
354
			public void widgetSelected(SelectionEvent e) {
355
				handleAddAll();
356
			}
357
		});
358
		SWTUtil.setButtonDimensionHint(fAddAllButton);
359
360
		fRemoveButton = new Button(container, SWT.PUSH);
361
		fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove);
362
		fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
363
		fRemoveButton.addSelectionListener(new SelectionAdapter() {
364
			public void widgetSelected(SelectionEvent e) {
365
				handleRemove();
366
			}
367
		});
368
		SWTUtil.setButtonDimensionHint(fRemoveButton);
369
370
		fRemoveAllButton = new Button(container, SWT.PUSH);
371
		fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll);
372
		fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
373
		fRemoveAllButton.addSelectionListener(new SelectionAdapter() {
374
			public void widgetSelected(SelectionEvent e) {
375
				handleRemoveAll();
376
			}
377
		});
378
		SWTUtil.setButtonDimensionHint(fRemoveAllButton);
379
380
		fCountLabel = new Label(container, SWT.NONE);
381
		fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
382
		comp.setContent(container);
383
		comp.setMinHeight(250);
384
		comp.setExpandHorizontal(true);
385
		comp.setExpandVertical(true);
386
		return container;
387
	}
388
389
	private Composite createScrollArea(Composite parent) {
390
		Group container = new Group(parent, SWT.NONE);
391
		GridLayout layout = new GridLayout(2, false);
392
		layout.marginWidth = layout.marginHeight = 6;
393
		container.setLayout(layout);
394
395
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
396
		gd.horizontalSpan = 3;
397
		container.setLayoutData(gd);
398
		container.setText(PDEUIMessages.InternationalizeWizard_PluginPage_filter);
399
400
		Label filterLabel = new Label(container, SWT.NONE);
401
		filterLabel.setText(PDEUIMessages.ImportWizard_DetailedPage_search);
402
403
		fFilterText = new Text(container, SWT.BORDER);
404
		fFilterText.setText(""); //$NON-NLS-1$
405
		gd = new GridData(GridData.FILL_HORIZONTAL);
406
		fFilterText.setLayoutData(gd);
407
408
		return container;
409
	}
410
411
	public void setVisible(boolean visible) {
412
		super.setVisible(visible);
413
	}
414
415
	protected void refreshPage() {
416
		fSelectedListViewer.getTable().removeAll();
417
		fSelected = new HashMap();
418
		fAvailableListViewer.refresh();
419
		pageChanged();
420
	}
421
422
	protected void pageChanged() {
423
		pageChanged(false, false);
424
	}
425
426
	protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) {
427
		updateCount();
428
		updateButtonEnablement(doAddEnablement, doRemoveEnablement);
429
		setPageComplete(fSelectedListViewer.getTable().getItemCount() > 0);
430
	}
431
432
	private void updateCount() {
433
		fCountLabel.setText(NLS.bind(PDEUIMessages.ImportWizard_DetailedPage_count, (new String[] {new Integer(fSelectedListViewer.getTable().getItemCount()).toString(), new Integer(fAvailableListViewer.getTable().getItemCount() + fSelectedListViewer.getTable().getItemCount()).toString()})));
434
		fCountLabel.getParent().layout();
435
	}
436
437
	private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
438
		int availableCount = fAvailableListViewer.getTable().getItemCount();
439
		int importCount = fSelectedListViewer.getTable().getItemCount();
440
441
		if (doAddEnablement)
442
			updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
443
		if (doRemoveEnablement)
444
			updateSelectionBasedEnablement(fSelectedListViewer.getSelection(), false);
445
446
		fAddAllButton.setEnabled(availableCount > 0);
447
		fRemoveAllButton.setEnabled(importCount > 0);
448
	}
449
450
	private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
451
		if (available)
452
			fAddButton.setEnabled(!theSelection.isEmpty());
453
		else
454
			fRemoveButton.setEnabled(!theSelection.isEmpty());
455
	}
456
457
	private void handleAdd() {
458
		IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
459
		if (ssel.size() > 0) {
460
			Table table = fAvailableListViewer.getTable();
461
			int index = table.getSelectionIndices()[0];
462
			Object[] selection = ssel.toArray();
463
			setBlockSelectionListeners(true);
464
			setRedraw(false);
465
			for (int i = 0; i < selection.length; i++) {
466
				doAdd(selection[i]);
467
			}
468
			setRedraw(true);
469
			setBlockSelectionListeners(false);
470
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
471
			pageChanged(true, false);
472
		}
473
	}
474
475
	private void handleAddAll() {
476
		TableItem[] items = fAvailableListViewer.getTable().getItems();
477
478
		ArrayList data = new ArrayList();
479
		for (int i = 0; i < items.length; i++) {
480
			data.add(items[i].getData());
481
		}
482
		if (data.size() > 0) {
483
			Object[] datas = data.toArray();
484
			setBlockSelectionListeners(true);
485
			setRedraw(false);
486
			for (int i = 0; i < datas.length; i++) {
487
				doAdd(datas[i]);
488
			}
489
			setRedraw(true);
490
			setBlockSelectionListeners(false);
491
			pageChanged(true, false);
492
		}
493
	}
494
495
	private void handleRemove() {
496
		IStructuredSelection ssel = (IStructuredSelection) fSelectedListViewer.getSelection();
497
		if (ssel.size() > 0) {
498
			Table table = fSelectedListViewer.getTable();
499
			int index = table.getSelectionIndices()[0];
500
			Object[] selection = ssel.toArray();
501
			setBlockSelectionListeners(true);
502
			setRedraw(false);
503
			for (int i = 0; i < selection.length; i++) {
504
				doRemove(selection[i]);
505
			}
506
			setRedraw(true);
507
			setBlockSelectionListeners(false);
508
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
509
			pageChanged(false, true);
510
		}
511
	}
512
513
	private void doAdd(Object o) {
514
		fInternationalizeModelTable.removeModel(o);
515
		fSelectedListViewer.add(o);
516
		fAvailableListViewer.remove(o);
517
		fSelected.put(o, null);
518
	}
519
520
	private void doRemove(Object o) {
521
		fInternationalizeModelTable.addModel(o);
522
		fSelected.remove(o);
523
		fSelectedListViewer.remove(o);
524
		fAvailableListViewer.add(o);
525
	}
526
527
	// used to prevent flicker during operations that move items between lists
528
	private void setRedraw(boolean redraw) {
529
		fAvailableListViewer.getTable().setRedraw(redraw);
530
		fSelectedListViewer.getTable().setRedraw(redraw);
531
	}
532
533
	private void handleRemoveAll() {
534
		TableItem[] items = fSelectedListViewer.getTable().getItems();
535
536
		ArrayList data = new ArrayList();
537
		for (int i = 0; i < items.length; i++) {
538
			data.add(items[i].getData());
539
		}
540
		if (data.size() > 0) {
541
			Object[] datas = data.toArray();
542
			setBlockSelectionListeners(true);
543
			setRedraw(false);
544
			for (int i = 0; i < datas.length; i++) {
545
				doRemove(datas[i]);
546
			}
547
			setRedraw(true);
548
			setBlockSelectionListeners(false);
549
			pageChanged(false, true);
550
		}
551
	}
552
553
	public void dispose() {
554
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
555
		PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this);
556
	}
557
558
	private void setBlockSelectionListeners(boolean blockSelectionListeners) {
559
		fBlockSelectionListeners = blockSelectionListeners;
560
	}
561
562
	public boolean isCurrentPage() {
563
		return super.isCurrentPage();
564
	}
565
566
	public boolean canFlipToNextPage() {
567
		if (fSelectedListViewer.getTable().getItems().length > 0) {
568
			return true;
569
		}
570
		return false;
571
	}
572
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java (+193 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.util.*;
4
import org.eclipse.core.resources.IProject;
5
import org.eclipse.jface.action.IAction;
6
import org.eclipse.jface.dialogs.IDialogSettings;
7
import org.eclipse.jface.viewers.IStructuredSelection;
8
import org.eclipse.jface.viewers.StructuredSelection;
9
import org.eclipse.jface.wizard.IWizardPage;
10
import org.eclipse.jface.wizard.Wizard;
11
import org.eclipse.pde.core.plugin.IPluginModelBase;
12
import org.eclipse.pde.internal.core.plugin.ExternalPluginModel;
13
import org.eclipse.pde.internal.ui.*;
14
import org.eclipse.ui.IImportWizard;
15
import org.eclipse.ui.IWorkbench;
16
17
/**
18
 * An InternationalizeWizard is responsible for internationalizing a list of
19
 * specified plug-ins (workspace and external) to a set of specified locales.
20
 * This involves creating an NLS fragment project for every plug-in, which would
21
 * contain properties files for each specified locale. The first page of the wizard
22
 * allows the user to select the desired plug-ins and the second page the desired
23
 * locales. Also, the wizard ensures the plug-ins are externalized before proceeding
24
 * with internationlization.
25
 * 
26
 * @author Team Azure
27
 *
28
 */
29
public class InternationalizeWizard extends Wizard implements IImportWizard {
30
31
	private static final String STORE_SECTION = "InternationalizeWizard"; //$NON-NLS-1$
32
33
	private IAction action;
34
	private IStructuredSelection selection;
35
36
	//An intermediate selection passed to the ExternalizeStringsWizard
37
	private IStructuredSelection externalizeSelection;
38
39
	private InternationalizeWizardPluginPage page1;
40
	private InternationalizeWizardLocalePage page2;
41
42
	//Contains the list of plug-ins to be internationalized
43
	private InternationalizeModelTable fInternationalizePluginModelTable;
44
45
	//Contains the list of locales
46
	private InternationalizeModelTable fInternationalizeLocaleModelTable;
47
48
	public InternationalizeWizard(IAction action, InternationalizeModelTable pluginTable) {
49
		fInternationalizePluginModelTable = pluginTable;
50
		populateLocaleModelTable();
51
		IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings();
52
		setDialogSettings(getSettingsSection(masterSettings));
53
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_EXTSTR_WIZ);
54
		setWindowTitle(PDEUIMessages.InternationalizeWizard_title);
55
		this.action = action;
56
	}
57
58
	/**
59
	 * Populates the local InternationalizeModelTable with the list of all
60
	 * available locales
61
	 */
62
	private void populateLocaleModelTable() {
63
		fInternationalizeLocaleModelTable = new InternationalizeModelTable();
64
		for (Locale locale : Locale.getAvailableLocales()) {
65
			fInternationalizeLocaleModelTable.addModel(locale);
66
		}
67
	}
68
69
	/**
70
	 * Initialises selections
71
	 */
72
	public void init(IWorkbench workbench, IStructuredSelection selection) {
73
		this.selection = selection;
74
		externalizeSelection = this.selection;
75
	}
76
77
	/**
78
	 * Adds the plug-in and locale pages to the wizard
79
	 */
80
	public void addPages() {
81
		setNeedsProgressMonitor(true);
82
		page1 = new InternationalizeWizardPluginPage(fInternationalizePluginModelTable, "Plug-ins"); //$NON-NLS-1$
83
		addPage(page1);
84
85
		page2 = new InternationalizeWizardLocalePage(fInternationalizeLocaleModelTable, "Locales"); //$NON-NLS-1$
86
		addPage(page2);
87
	}
88
89
	/**
90
	 * 
91
	 * @param master
92
	 * @return the created setting for the InternationalizeWizard
93
	 */
94
	private IDialogSettings getSettingsSection(IDialogSettings master) {
95
		IDialogSettings setting = master.getSection(STORE_SECTION);
96
		if (setting == null) {
97
			setting = master.addNewSection(STORE_SECTION);
98
		}
99
		return setting;
100
	}
101
102
	/**
103
	 * 
104
	 * @return the list of plug-ins selected for internationalization
105
	 */
106
	private List getPluginModelsForInternationalization() {
107
		return page1.getModelsToInternationalize();
108
	}
109
110
	/**
111
	 * 
112
	 * @return the list of locales specified for internationalization
113
	 */
114
	private List getLocalesForInternationalization() {
115
		return page2.getLocalesForInternationalization();
116
	}
117
118
	public boolean performFinish() {
119
		page1.storeSettings();
120
121
		/*ArrayList pluginModels = (ArrayList) getPluginModelsForInternationalization();
122
		final IPluginModelBase[] plugins = (IPluginModelBase[]) pluginModels.toArray(new IPluginModelBase[pluginModels.size()]);
123
124
		ArrayList localeModels = (ArrayList) getLocalesForInternationalization();
125
		final Locale[] locales = (Locale[]) localeModels.toArray(new IPluginModelBase[pluginModels.size()]);
126
		 */
127
128
		//Generate an NL fragment project for each of the selected plug-ins with the specified locales
129
		new NLSFragmentsGenerator(getPluginModelsForInternationalization(), getLocalesForInternationalization(), this.getContainer());
130
		return true;
131
	}
132
133
	/**
134
	 * 
135
	 * @param currentPage
136
	 * @return the next wizard page
137
	 */
138
	public IWizardPage getNextPage(IWizardPage currentPage) {
139
		if (currentPage.equals(page1)) {
140
			//page.setVisible(false);
141
			ensurePluginsAreExternalized();
142
			//page.setVisible(true);
143
144
			return page2;
145
		}
146
		return currentPage;
147
	}
148
149
	/**
150
	 * 
151
	 * @param currentPage
152
	 * @return the previous wizard page
153
	 */
154
	public IWizardPage getPreviousPage(IWizardPage currentPage) {
155
		return currentPage.equals(page1) ? null : page1;
156
	}
157
158
	public boolean canFinish() {
159
		return !page1.isCurrentPage() && page1.getNextPage().isPageComplete();
160
	}
161
162
	/**
163
	 * Checks whether or not the selected plug-ins are already externalized. This
164
	 * method invokes the ExternalizeStringsWizard on the selected plug-ins.
165
	 */
166
	public void ensurePluginsAreExternalized() {
167
		GetNonExternalizedStringsAction externalize = new GetNonExternalizedStringsAction();
168
169
		List<IProject> projects = new ArrayList<IProject>();
170
		List<IPluginModelBase> pluginModels = getPluginModelsForInternationalization();
171
		selection = new StructuredSelection(pluginModels); //Save the plug-ins selected for internationalization in a StructuredSelection
172
		for (IPluginModelBase pluginModel : pluginModels) {
173
			//Externalize only workspace plug-ins since external plug-ins are already externalized
174
			if (!(pluginModel instanceof ExternalPluginModel)) {
175
				IProject project = pluginModel.getUnderlyingResource().getProject();
176
				projects.add(project);
177
			}
178
		}
179
180
		//Set the selection for the non-externalized plug-ins that 
181
		//should be passed to the ExternalizeStringsWizard
182
		externalizeSelection = new StructuredSelection(projects);
183
184
		externalize.selectionChanged(action, externalizeSelection);
185
		externalize.setExternalizeSelectedPluginsOnly(true);
186
		externalize.setSkipMessageDialog(true);
187
		externalize.run(action);
188
	}
189
190
	public boolean performCancel() {
191
		return super.performCancel();
192
	}
193
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeOperation.java (+93 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.lang.reflect.InvocationTargetException;
4
import java.util.ArrayList;
5
import org.eclipse.core.resources.IFile;
6
import org.eclipse.core.resources.IProject;
7
import org.eclipse.core.runtime.IProgressMonitor;
8
import org.eclipse.jface.operation.IRunnableWithProgress;
9
import org.eclipse.jface.viewers.ISelection;
10
import org.eclipse.jface.viewers.IStructuredSelection;
11
import org.eclipse.pde.core.plugin.IPluginModelBase;
12
import org.eclipse.pde.core.plugin.PluginRegistry;
13
import org.eclipse.pde.internal.core.WorkspaceModelManager;
14
import org.eclipse.pde.internal.ui.PDEUIMessages;
15
16
/**
17
 * InternationalizeOperation is responsible for populating a plug-in model table
18
 * containing the list of plug-ins (workspace and external) prior to running the
19
 * wizard. An instance of this class must be created before creating an
20
 * InternationlizeWizard instance.
21
 * 
22
 * @author Team Azure
23
 *
24
 */
25
public class InternationalizeOperation implements IRunnableWithProgress {
26
27
	private ISelection fSelection;
28
	private ArrayList fSelectedModels;
29
	private InternationalizeModelTable fModelPluginTable;
30
	private boolean fCanceled;
31
32
	/**
33
	 * 
34
	 * @param selection represents the preselected plug-in projects in the workbench
35
	 */
36
	public InternationalizeOperation(ISelection selection) {
37
		fSelection = selection;
38
	}
39
40
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
41
42
		if (fSelection instanceof IStructuredSelection) {
43
44
			Object[] elems = ((IStructuredSelection) fSelection).toArray();
45
46
			fSelectedModels = new ArrayList(elems.length);
47
			for (int i = 0; i < elems.length; i++) {
48
				//If a file was selected, get its parent project
49
				if (elems[i] instanceof IFile)
50
					elems[i] = ((IFile) elems[i]).getProject();
51
52
				//Add the project to the preselected model list
53
				if (elems[i] instanceof IProject && WorkspaceModelManager.isPluginProject((IProject) elems[i]) && !WorkspaceModelManager.isBinaryProject((IProject) elems[i]))
54
					fSelectedModels.add(elems[i]);
55
			}
56
		}
57
58
		//Get all models (workspace and external) excluding fragment models
59
		IPluginModelBase[] pluginModels = PluginRegistry.getAllModels(false);
60
		monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length);
61
62
		//Populate list to an InternationalizeModelTable
63
		fModelPluginTable = new InternationalizeModelTable();
64
		for (int i = 0; i < pluginModels.length; i++) {
65
			fModelPluginTable.addToModelTable(pluginModels[i], pluginModels[i].getUnderlyingResource() != null ? selected(pluginModels[i].getUnderlyingResource().getProject()) : false);
66
		}
67
	}
68
69
	/**
70
	 * 
71
	 * @return whether or not the operation was cancelled
72
	 */
73
	public boolean wasCanceled() {
74
		return fCanceled;
75
	}
76
77
	/**
78
	 * 
79
	 * @param project
80
	 * @return whether or not the project was preselected
81
	 */
82
	public boolean selected(IProject project) {
83
		return fSelectedModels.contains(project);
84
	}
85
86
	/**
87
	 * 
88
	 * @return the InternationalizeModelTable containing the plug-ins
89
	 */
90
	public InternationalizeModelTable getPluginTable() {
91
		return fModelPluginTable;
92
	}
93
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardPluginPage.java (+653 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.ui.nls;
5
6
import java.util.*;
7
import java.util.List;
8
import java.util.regex.Pattern;
9
import org.eclipse.core.runtime.*;
10
import org.eclipse.jface.dialogs.Dialog;
11
import org.eclipse.jface.dialogs.IDialogSettings;
12
import org.eclipse.jface.layout.GridLayoutFactory;
13
import org.eclipse.jface.viewers.*;
14
import org.eclipse.jface.wizard.IWizardContainer;
15
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.pde.core.IModelProviderEvent;
18
import org.eclipse.pde.core.IModelProviderListener;
19
import org.eclipse.pde.core.plugin.*;
20
import org.eclipse.pde.internal.core.ClasspathUtilCore;
21
import org.eclipse.pde.internal.core.PDECore;
22
import org.eclipse.pde.internal.core.util.PatternConstructor;
23
import org.eclipse.pde.internal.ui.*;
24
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
25
import org.eclipse.pde.internal.ui.util.SWTUtil;
26
import org.eclipse.pde.internal.ui.wizards.ListUtil;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.custom.ScrolledComposite;
29
import org.eclipse.swt.events.*;
30
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.*;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.progress.WorkbenchJob;
35
36
/**
37
 * The first page of the InternationalizeWizard. This page allows the user to 
38
 * select the desired plug-ins for internationalization. These could be plug-ins
39
 * in the user's workspace or external ones.
40
 * 
41
 * @author Team Azure
42
 *
43
 */
44
public class InternationalizeWizardPluginPage extends WizardPage implements IModelProviderListener {
45
46
	public static final String PAGE_NAME = "InternationalizeWizardPluginPage"; //$NON-NLS-1$
47
48
	protected IPluginModelBase[] fModels = new IPluginModelBase[0];
49
	//private String fLocation;
50
51
	private boolean fRefreshNeeded = true;
52
53
	private Label fCountLabel; //Displays "x out of y selected"
54
55
	private TableViewer fAvailableListViewer; //All available plug-ins
56
	protected TableViewer fSelectedListViewer; //Selected plug-ins
57
58
	private WorkbenchJob fFilterJob;
59
	private Text fFilterText;
60
	private AvailableFilter fFilter;
61
62
	// Used to track the selection in a HashMap so as to filter
63
	// selected items out of the available item list
64
	private HashMap fSelected;
65
66
	// Used to block the selection listeners from updating button enablement
67
	// when programatically removing items
68
	private boolean fBlockSelectionListeners;
69
	private Button fAddButton;
70
	private Button fAddAllButton;
71
	private Button fRemoveButton;
72
	private Button fRemoveAllButton;
73
74
	// Used to store the plug-ins
75
	private InternationalizeModelTable fInternationalizeModelTable;
76
77
	private class AvailableFilter extends ViewerFilter {
78
		private Pattern fPattern;
79
80
		public AvailableFilter() {
81
			setPattern("*"); //$NON-NLS-1$
82
		}
83
84
		public boolean select(Viewer viewer, Object parentElement, Object element) {
85
			// filter out any items that are currently selected
86
			// on a full refresh, these will have been added back to the list
87
			if (fSelected.containsKey(element))
88
				return false;
89
			if (!(element instanceof IPluginModelBase))
90
				return false;
91
92
			String itemID = ((IPluginModelBase) element).getPluginBase().getId();
93
			if (fPattern.matcher(itemID).matches())
94
				return true;
95
			return false;
96
		}
97
98
		public boolean setPattern(String newPattern) {
99
			if (!newPattern.endsWith("*")) //$NON-NLS-1$
100
				newPattern += "*"; //$NON-NLS-1$
101
			if (!newPattern.startsWith("*")) //$NON-NLS-1$
102
				newPattern = "*" + newPattern; //$NON-NLS-1$
103
			if (fPattern != null) {
104
				String oldPattern = fPattern.pattern();
105
				if (newPattern.equals(oldPattern))
106
					return false;
107
			}
108
			fPattern = PatternConstructor.createPattern(newPattern, true);
109
			return true;
110
		}
111
	}
112
113
	private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
114
		/**
115
		 * @return the list of available non-selected plug-ins
116
		 */
117
		public Object[] getElements(Object parent) {
118
			return fInternationalizeModelTable.getModels();
119
		}
120
	}
121
122
	private class SelectedContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
123
		/**
124
		 * @return the list of selected plug-ins
125
		 */
126
		public Object[] getElements(Object parent) {
127
			return fInternationalizeModelTable.getPreSelected();
128
		}
129
	}
130
131
	public InternationalizeWizardPluginPage(InternationalizeModelTable modelTable, String pageName) {
132
133
		super(pageName);
134
		setTitle(PDEUIMessages.InternationalizeWizard_PluginPage_pageTitle);
135
		setDescription(PDEUIMessages.InternationalizeWizard_PluginPage_pageDescription);
136
137
		PDEPlugin.getDefault().getLabelProvider().connect(this);
138
		PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this);
139
140
		fInternationalizeModelTable = modelTable;
141
		fSelected = new HashMap();
142
143
		IWizardContainer container = getContainer();
144
		if (container != null)
145
			container.updateButtons();
146
	}
147
148
	/**
149
	 * Adds a filter to the list of available plug-ins
150
	 */
151
	private void addFilter() {
152
		fFilter = new AvailableFilter();
153
		fAvailableListViewer.addFilter(fFilter);
154
		fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$
155
			public IStatus runInUIThread(IProgressMonitor monitor) {
156
				handleFilter();
157
				return Status.OK_STATUS;
158
			}
159
		};
160
		fFilterJob.setSystem(true);
161
	}
162
163
	/**
164
	 * Handles changes to the list based on changes to the text field.
165
	 */
166
	private void handleFilter() {
167
		boolean changed = false;
168
		String newFilter;
169
		if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0)
170
			newFilter = "*"; //$NON-NLS-1$
171
		changed = fFilter.setPattern(newFilter);
172
		if (changed) {
173
			fAvailableListViewer.getTable().setRedraw(false);
174
			fAvailableListViewer.refresh();
175
			fAvailableListViewer.getTable().setRedraw(true);
176
			updateButtonEnablement(false, false);
177
		}
178
	}
179
180
	/* (non-Javadoc)
181
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
182
	 */
183
	public void createControl(Composite parent) {
184
		Composite container = new Composite(parent, SWT.NONE);
185
		GridLayout layout = new GridLayout();
186
		layout.numColumns = 3;
187
		layout.makeColumnsEqualWidth = false;
188
		layout.horizontalSpacing = 5;
189
		layout.verticalSpacing = 10;
190
		container.setLayout(layout);
191
192
		createScrollArea(container);
193
		createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
194
		createButtonArea(container);
195
		createInternationalizeList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
196
		updateCount();
197
198
		// create container for buttons
199
		Composite buttonContainer = new Composite(container, SWT.NONE);
200
		buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create());
201
202
		addViewerListeners();
203
		addFilter();
204
205
		initialize();
206
		setControl(container);
207
		Dialog.applyDialogFont(container);
208
		PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE);
209
	}
210
211
	/**
212
	 * 
213
	 * @param parent
214
	 * @return the container holding the available plug-ins list
215
	 */
216
	private Composite createAvailableList(Composite parent) {
217
		Composite container = new Composite(parent, SWT.NONE);
218
		GridLayout layout = new GridLayout();
219
		layout.marginWidth = 0;
220
		layout.marginHeight = 0;
221
		container.setLayout(layout);
222
		container.setLayoutData(new GridData());
223
224
		Label label = new Label(container, SWT.NONE);
225
		label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_availableList);
226
227
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
228
		GridData gd = new GridData(GridData.FILL_BOTH);
229
		gd.heightHint = 200;
230
		gd.widthHint = 225;
231
		table.setLayoutData(gd);
232
233
		fAvailableListViewer = new TableViewer(table);
234
		fAvailableListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
235
		fAvailableListViewer.setContentProvider(new ContentProvider());
236
		fAvailableListViewer.setInput(PDECore.getDefault().getModelManager());
237
		fAvailableListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
238
239
		return container;
240
	}
241
242
	protected Composite createInternationalizeList(Composite parent) {
243
		Composite container = new Composite(parent, SWT.NONE);
244
		GridLayout layout = new GridLayout();
245
		layout.marginWidth = 0;
246
		layout.marginHeight = 0;
247
		container.setLayout(layout);
248
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
249
250
		Label label = new Label(container, SWT.NONE);
251
		label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_internationalizeList);
252
253
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
254
		GridData gd = new GridData(GridData.FILL_BOTH);
255
		gd.widthHint = 225;
256
		table.setLayoutData(gd);
257
258
		fSelectedListViewer = new TableViewer(table);
259
		fSelectedListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
260
		fSelectedListViewer.setContentProvider(new SelectedContentProvider());
261
		fSelectedListViewer.setInput(PDECore.getDefault().getModelManager().getExternalModelManager());
262
		fSelectedListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
263
		return container;
264
	}
265
266
	protected boolean isRefreshNeeded() {
267
		if (fRefreshNeeded) {
268
			fRefreshNeeded = false;
269
			return true;
270
		}
271
		/*if (fLocation == null) {
272
			return true;
273
		}*/
274
		return false;
275
	}
276
277
	private IPluginModelBase findModel(String id) {
278
		for (int i = 0; i < fModels.length; i++) {
279
			String modelId = fModels[i].getPluginBase().getId();
280
			if (modelId != null && modelId.equals(id))
281
				return fModels[i];
282
		}
283
		return null;
284
	}
285
286
	private IFragmentModel[] findFragments(IPlugin plugin) {
287
		ArrayList result = new ArrayList();
288
		for (int i = 0; i < fModels.length; i++) {
289
			if (fModels[i] instanceof IFragmentModel) {
290
				IFragment fragment = ((IFragmentModel) fModels[i]).getFragment();
291
				if (plugin.getId().equalsIgnoreCase(fragment.getPluginId())) {
292
					result.add(fModels[i]);
293
				}
294
			}
295
		}
296
		return (IFragmentModel[]) result.toArray(new IFragmentModel[result.size()]);
297
	}
298
299
	protected void addPluginAndDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) {
300
301
		boolean containsVariable = false;
302
		if (!selected.contains(model)) {
303
			selected.add(model);
304
			boolean hasextensibleAPI = ClasspathUtilCore.hasExtensibleAPI(model);
305
			if (!addFragments && !hasextensibleAPI && model instanceof IPluginModel) {
306
				IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
307
				for (int i = 0; i < libraries.length; i++) {
308
					if (ClasspathUtilCore.containsVariables(libraries[i].getName())) {
309
						containsVariable = true;
310
						break;
311
					}
312
				}
313
			}
314
			addDependencies(model, selected, addFragments || containsVariable || hasextensibleAPI);
315
		}
316
	}
317
318
	protected void addDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) {
319
320
		IPluginImport[] required = model.getPluginBase().getImports();
321
		if (required.length > 0) {
322
			for (int i = 0; i < required.length; i++) {
323
				IPluginModelBase found = findModel(required[i].getId());
324
				if (found != null) {
325
					addPluginAndDependencies(found, selected, addFragments);
326
				}
327
			}
328
		}
329
330
		if (addFragments) {
331
			if (model instanceof IPluginModel) {
332
				IFragmentModel[] fragments = findFragments(((IPluginModel) model).getPlugin());
333
				for (int i = 0; i < fragments.length; i++) {
334
					addPluginAndDependencies(fragments[i], selected, addFragments);
335
				}
336
			} else {
337
				IFragment fragment = ((IFragmentModel) model).getFragment();
338
				IPluginModelBase found = findModel(fragment.getPluginId());
339
				if (found != null) {
340
					addPluginAndDependencies(found, selected, addFragments);
341
				}
342
			}
343
		}
344
	}
345
346
	public List getModelsToInternationalize() {
347
		TableItem[] items = fSelectedListViewer.getTable().getItems();
348
		List result = new ArrayList();
349
		for (int i = 0; i < items.length; i++) {
350
			result.add(items[i].getData());
351
		}
352
		return result;
353
	}
354
355
	public void storeSettings() {
356
		IDialogSettings settings = getDialogSettings();
357
	}
358
359
	/* (non-Javadoc)
360
	 * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent)
361
	 */
362
	public void modelsChanged(IModelProviderEvent event) {
363
		fRefreshNeeded = true;
364
	}
365
366
	private void initialize() {
367
		updateButtonEnablement(true, true);
368
		setPageComplete(false);
369
	}
370
371
	private void addViewerListeners() {
372
		fAvailableListViewer.addDoubleClickListener(new IDoubleClickListener() {
373
			public void doubleClick(DoubleClickEvent event) {
374
				handleAdd();
375
			}
376
		});
377
378
		fSelectedListViewer.addDoubleClickListener(new IDoubleClickListener() {
379
			public void doubleClick(DoubleClickEvent event) {
380
				handleRemove();
381
			}
382
		});
383
384
		fAvailableListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
385
			public void selectionChanged(SelectionChangedEvent event) {
386
				if (!fBlockSelectionListeners)
387
					updateSelectionBasedEnablement(event.getSelection(), true);
388
			}
389
		});
390
391
		fSelectedListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
392
			public void selectionChanged(SelectionChangedEvent event) {
393
				if (!fBlockSelectionListeners)
394
					updateSelectionBasedEnablement(event.getSelection(), false);
395
			}
396
		});
397
398
		fFilterText.addModifyListener(new ModifyListener() {
399
			public void modifyText(ModifyEvent e) {
400
				fFilterJob.cancel();
401
				fFilterJob.schedule(200);
402
			}
403
		});
404
405
	}
406
407
	private Composite createButtonArea(Composite parent) {
408
		ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
409
		GridLayout layout = new GridLayout();
410
		layout.marginWidth = layout.marginHeight = 0;
411
		comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
412
		Composite container = new Composite(comp, SWT.NONE);
413
		layout = new GridLayout();
414
		layout.marginWidth = 0;
415
		layout.marginTop = 50;
416
		container.setLayout(layout);
417
		GridData gd = new GridData(GridData.FILL_VERTICAL);
418
		gd.verticalIndent = 15;
419
		container.setLayoutData(gd);
420
421
		fAddButton = new Button(container, SWT.PUSH);
422
		fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add);
423
		fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
424
		fAddButton.addSelectionListener(new SelectionAdapter() {
425
			public void widgetSelected(SelectionEvent e) {
426
				handleAdd();
427
			}
428
		});
429
		SWTUtil.setButtonDimensionHint(fAddButton);
430
431
		fAddAllButton = new Button(container, SWT.PUSH);
432
		fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll);
433
		fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
434
		fAddAllButton.addSelectionListener(new SelectionAdapter() {
435
			public void widgetSelected(SelectionEvent e) {
436
				handleAddAll();
437
			}
438
		});
439
		SWTUtil.setButtonDimensionHint(fAddAllButton);
440
441
		fRemoveButton = new Button(container, SWT.PUSH);
442
		fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove);
443
		fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
444
		fRemoveButton.addSelectionListener(new SelectionAdapter() {
445
			public void widgetSelected(SelectionEvent e) {
446
				handleRemove();
447
			}
448
		});
449
		SWTUtil.setButtonDimensionHint(fRemoveButton);
450
451
		fRemoveAllButton = new Button(container, SWT.PUSH);
452
		fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll);
453
		fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
454
		fRemoveAllButton.addSelectionListener(new SelectionAdapter() {
455
			public void widgetSelected(SelectionEvent e) {
456
				handleRemoveAll();
457
			}
458
		});
459
		SWTUtil.setButtonDimensionHint(fRemoveAllButton);
460
461
		fCountLabel = new Label(container, SWT.NONE);
462
		fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
463
		comp.setContent(container);
464
		comp.setMinHeight(250);
465
		comp.setExpandHorizontal(true);
466
		comp.setExpandVertical(true);
467
		return container;
468
	}
469
470
	private Composite createScrollArea(Composite parent) {
471
		Group container = new Group(parent, SWT.NONE);
472
		GridLayout layout = new GridLayout(2, false);
473
		layout.marginWidth = layout.marginHeight = 6;
474
		container.setLayout(layout);
475
476
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
477
		gd.horizontalSpan = 3;
478
		container.setLayoutData(gd);
479
		container.setText(PDEUIMessages.InternationalizeWizard_PluginPage_filter);
480
481
		Label filterLabel = new Label(container, SWT.NONE);
482
		filterLabel.setText(PDEUIMessages.ImportWizard_DetailedPage_search);
483
484
		fFilterText = new Text(container, SWT.BORDER);
485
		fFilterText.setText(""); //$NON-NLS-1$
486
		gd = new GridData(GridData.FILL_HORIZONTAL);
487
		fFilterText.setLayoutData(gd);
488
489
		return container;
490
	}
491
492
	public void setVisible(boolean visible) {
493
		super.setVisible(visible);
494
	}
495
496
	protected void refreshPage() {
497
		fSelectedListViewer.getTable().removeAll();
498
		fSelected = new HashMap();
499
		fAvailableListViewer.refresh();
500
		pageChanged();
501
	}
502
503
	protected void pageChanged() {
504
		pageChanged(false, false);
505
	}
506
507
	protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) {
508
		updateCount();
509
		updateButtonEnablement(doAddEnablement, doRemoveEnablement);
510
		setPageComplete(fSelectedListViewer.getTable().getItemCount() > 0);
511
	}
512
513
	private void updateCount() {
514
		fCountLabel.setText(NLS.bind(PDEUIMessages.ImportWizard_DetailedPage_count, (new String[] {new Integer(fSelectedListViewer.getTable().getItemCount()).toString(), new Integer(fAvailableListViewer.getTable().getItemCount() + fSelectedListViewer.getTable().getItemCount()).toString()})));
515
		fCountLabel.getParent().layout();
516
	}
517
518
	private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
519
		int availableCount = fAvailableListViewer.getTable().getItemCount();
520
		int importCount = fSelectedListViewer.getTable().getItemCount();
521
522
		if (doAddEnablement)
523
			updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
524
		if (doRemoveEnablement)
525
			updateSelectionBasedEnablement(fSelectedListViewer.getSelection(), false);
526
527
		fAddAllButton.setEnabled(availableCount > 0);
528
		fRemoveAllButton.setEnabled(importCount > 0);
529
	}
530
531
	private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
532
		if (available)
533
			fAddButton.setEnabled(!theSelection.isEmpty());
534
		else
535
			fRemoveButton.setEnabled(!theSelection.isEmpty());
536
	}
537
538
	private void handleAdd() {
539
		IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
540
		if (ssel.size() > 0) {
541
			Table table = fAvailableListViewer.getTable();
542
			int index = table.getSelectionIndices()[0];
543
			Object[] selection = ssel.toArray();
544
			setBlockSelectionListeners(true);
545
			setRedraw(false);
546
			for (int i = 0; i < selection.length; i++) {
547
				doAdd(selection[i]);
548
			}
549
			setRedraw(true);
550
			setBlockSelectionListeners(false);
551
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
552
			pageChanged(true, false);
553
		}
554
	}
555
556
	private void handleAddAll() {
557
		TableItem[] items = fAvailableListViewer.getTable().getItems();
558
559
		ArrayList data = new ArrayList();
560
		for (int i = 0; i < items.length; i++) {
561
			data.add(items[i].getData());
562
		}
563
		if (data.size() > 0) {
564
			Object[] datas = data.toArray();
565
			setBlockSelectionListeners(true);
566
			setRedraw(false);
567
			for (int i = 0; i < datas.length; i++) {
568
				doAdd(datas[i]);
569
			}
570
			setRedraw(true);
571
			setBlockSelectionListeners(false);
572
			pageChanged(true, false);
573
		}
574
	}
575
576
	private void handleRemove() {
577
		IStructuredSelection ssel = (IStructuredSelection) fSelectedListViewer.getSelection();
578
		if (ssel.size() > 0) {
579
			Table table = fSelectedListViewer.getTable();
580
			int index = table.getSelectionIndices()[0];
581
			Object[] selection = ssel.toArray();
582
			setBlockSelectionListeners(true);
583
			setRedraw(false);
584
			for (int i = 0; i < selection.length; i++) {
585
				doRemove(selection[i]);
586
			}
587
			setRedraw(true);
588
			setBlockSelectionListeners(false);
589
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
590
			pageChanged(false, true);
591
		}
592
	}
593
594
	private void doAdd(Object o) {
595
		fInternationalizeModelTable.removeModel(o);
596
		fSelectedListViewer.add(o);
597
		fAvailableListViewer.remove(o);
598
		fSelected.put(o, null);
599
	}
600
601
	private void doRemove(Object o) {
602
		fInternationalizeModelTable.addModel(o);
603
		fSelected.remove(o);
604
		fSelectedListViewer.remove(o);
605
		fAvailableListViewer.add(o);
606
	}
607
608
	// used to prevent flicker during operations that move items between lists
609
	private void setRedraw(boolean redraw) {
610
		fAvailableListViewer.getTable().setRedraw(redraw);
611
		fSelectedListViewer.getTable().setRedraw(redraw);
612
	}
613
614
	private void handleRemoveAll() {
615
		TableItem[] items = fSelectedListViewer.getTable().getItems();
616
617
		ArrayList data = new ArrayList();
618
		for (int i = 0; i < items.length; i++) {
619
			data.add(items[i].getData());
620
		}
621
		if (data.size() > 0) {
622
			Object[] datas = data.toArray();
623
			setBlockSelectionListeners(true);
624
			setRedraw(false);
625
			for (int i = 0; i < datas.length; i++) {
626
				doRemove(datas[i]);
627
			}
628
			setRedraw(true);
629
			setBlockSelectionListeners(false);
630
			pageChanged(false, true);
631
		}
632
	}
633
634
	public void dispose() {
635
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
636
		PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this);
637
	}
638
639
	private void setBlockSelectionListeners(boolean blockSelectionListeners) {
640
		fBlockSelectionListeners = blockSelectionListeners;
641
	}
642
643
	public boolean isCurrentPage() {
644
		return super.isCurrentPage();
645
	}
646
647
	public boolean canFlipToNextPage() {
648
		if (fSelectedListViewer.getTable().getItems().length > 0) {
649
			return true;
650
		}
651
		return false;
652
	}
653
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java (+91 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.util.ArrayList;
4
5
/**
6
 * 
7
 * Stores the list of BundlePluginModels and ExternalPluginModels to be passed to the
8
 * InternationalizeWizard. This class could also used to populate the list of locales
9
 * to which plug-ins will be internationalized.
10
 * 
11
 * @author Team Azure
12
 *
13
 */
14
public class InternationalizeModelTable {
15
	private ArrayList fModels;
16
	private ArrayList fPreSelected; //Models preselected by the user
17
18
	public InternationalizeModelTable() {
19
		fModels = new ArrayList();
20
		fPreSelected = new ArrayList();
21
	}
22
23
	/**
24
	 * Adds the model to the model table. Takes into consideration the specified
25
	 * selection.
26
	 * @param model
27
	 * @param selected
28
	 */
29
	public void addToModelTable(Object model, boolean selected) {
30
		if (selected)
31
			fPreSelected.add(model);
32
		else
33
			fModels.add(model);
34
	}
35
36
	/**
37
	 * Adds the model to the model table.
38
	 * @param model
39
	 */
40
	public void addModel(Object model) {
41
		fModels.add(model);
42
	}
43
44
	/**
45
	 * Removes the specified model from the model table.
46
	 * @param model
47
	 */
48
	public void removeModel(Object model) {
49
		fModels.remove(model);
50
	}
51
52
	/**
53
	 * 
54
	 * @return the number of models in the table
55
	 */
56
	public int getModelCount() {
57
		return fPreSelected.size() + fModels.size();
58
	}
59
60
	/**
61
	 * Returns the list of models stored in the model table
62
	 * @return the array of models
63
	 */
64
	public Object[] getModels() {
65
		return fModels.toArray();
66
	}
67
68
	/**
69
	 * Returns the list of preselected models stored in the model table
70
	 * @return the array of preselected models
71
	 */
72
	public Object[] getPreSelected() {
73
		return fPreSelected.toArray();
74
	}
75
76
	/**
77
	 * 
78
	 * @return whether or not the model table contains preselected models
79
	 */
80
	public boolean hasPreSelected() {
81
		return fPreSelected.size() > 0;
82
	}
83
84
	/**
85
	 * 
86
	 * @return whether or not the list of models is empty
87
	 */
88
	public boolean isEmpty() {
89
		return fModels.size() == 0;
90
	}
91
}

Return to bug 201998