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/nls/LocaleLabelProvider.java (+38 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.util.Locale;
4
import org.eclipse.jface.viewers.ILabelProvider;
5
import org.eclipse.jface.viewers.ILabelProviderListener;
6
import org.eclipse.swt.graphics.Image;
7
8
public class LocaleLabelProvider implements ILabelProvider {
9
10
	public Image getImage(Object element) {
11
		return null;
12
	}
13
14
	public String getText(Object element) {
15
		Locale locale = (Locale) element;
16
		String country = " (" + locale.getDisplayCountry() + ")";
17
		return locale.getDisplayLanguage() + (" ()".equals(country) ? "" : country);
18
	}
19
20
	public void addListener(ILabelProviderListener listener) {
21
		// TODO Auto-generated method stub
22
23
	}
24
25
	public void dispose() {
26
		// TODO Auto-generated method stub
27
	}
28
29
	public boolean isLabelProperty(Object element, String property) {
30
		// TODO Auto-generated method stub
31
		return false;
32
	}
33
34
	public void removeListener(ILabelProviderListener listener) {
35
		// TODO Auto-generated method stub
36
37
	}
38
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizationWizardPage.java (+44 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import org.eclipse.jface.resource.ImageDescriptor;
4
import org.eclipse.jface.wizard.WizardPage;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.layout.GridData;
7
import org.eclipse.swt.layout.GridLayout;
8
import org.eclipse.swt.widgets.*;
9
10
public abstract class InternationalizationWizardPage extends WizardPage {
11
12
	public InternationalizationWizardPage(String pageName) {
13
		super(pageName);
14
	}
15
16
	public InternationalizationWizardPage(String pageName, String title, ImageDescriptor titleImage) {
17
		super(pageName, title, titleImage);
18
	}
19
20
	protected Group createFilterContainer(Composite parent, String title, String label) {
21
		Group container = new Group(parent, SWT.NONE);
22
		GridLayout layout = new GridLayout(2, false);
23
		layout.marginWidth = layout.marginHeight = 6;
24
		container.setLayout(layout);
25
26
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
27
		gd.horizontalSpan = 3;
28
		container.setLayoutData(gd);
29
		container.setText(title);
30
31
		Label templateLabel = new Label(container, SWT.NONE);
32
		templateLabel.setText(label);
33
		return container;
34
	}
35
36
	protected Text createFilterText(Composite parent, String initial) {
37
		Text text = new Text(parent, SWT.BORDER);
38
		text.setText(initial);
39
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
40
		text.setLayoutData(gd);
41
		return text;
42
	}
43
44
}
(-)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 (+500 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 org.eclipse.core.runtime.*;
9
import org.eclipse.jface.dialogs.Dialog;
10
import org.eclipse.jface.dialogs.IDialogSettings;
11
import org.eclipse.jface.layout.GridLayoutFactory;
12
import org.eclipse.jface.viewers.*;
13
import org.eclipse.jface.wizard.IWizardContainer;
14
import org.eclipse.osgi.util.NLS;
15
import org.eclipse.pde.core.IModelProviderEvent;
16
import org.eclipse.pde.core.IModelProviderListener;
17
import org.eclipse.pde.internal.core.PDECore;
18
import org.eclipse.pde.internal.ui.*;
19
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
20
import org.eclipse.pde.internal.ui.util.SWTUtil;
21
import org.eclipse.pde.internal.ui.wizards.ListUtil;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.custom.ScrolledComposite;
24
import org.eclipse.swt.events.*;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.*;
28
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.progress.WorkbenchJob;
30
31
/**
32
 * @author Robbie
33
 *
34
 */
35
public class InternationalizeWizardLocalePage extends InternationalizationWizardPage implements IModelProviderListener {
36
37
	public static final String PAGE_NAME = "InternationalizeWizardLocalePage"; //$NON-NLS-1$
38
39
	protected Locale[] fModels = new Locale[0];
40
	private String fLocation;
41
42
	protected TableViewer fSelectedListViewer;
43
	private boolean fRefreshNeeded = true;
44
45
	private Label fCountLabel;
46
	private TableViewer fAvailableListViewer;
47
48
	// this job is used to delay the full filter refresh for 200 milliseconds in case the user is still typing
49
	private WorkbenchJob fFilterJob;
50
	private Text fFilterText;
51
	private AvailableFilter fFilter;
52
53
	// fSelected is used to track the selection in a HashMap so we can efficiently
54
	// filter selected items out of the available item list
55
	private HashMap fSelected;
56
	// used to block the selection listeners from updating button enablement when programatically removing items
57
	private boolean fBlockSelectionListeners;
58
	private Button fAddButton;
59
	private Button fAddAllButton;
60
	private Button fRemoveButton;
61
	private Button fRemoveAllButton;
62
63
	private InternationalizeModelTable fInternationalizeModelTable;
64
65
	private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
66
		public Object[] getElements(Object inputElement) {
67
			return ((InternationalizeModelTable) inputElement).getModels();
68
		}
69
	}
70
71
	public InternationalizeWizardLocalePage(InternationalizeModelTable modelTable, String pageName) {
72
		super(pageName);
73
		setTitle(PDEUIMessages.InternationalizeWizard_LocalePage_pageTitle);
74
		setDescription(PDEUIMessages.InternationalizeWizard_LocalePage_pageDescription);
75
76
		PDEPlugin.getDefault().getLabelProvider().connect(this);
77
		PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this);
78
79
		fInternationalizeModelTable = modelTable;
80
		fSelected = new HashMap();
81
82
		IWizardContainer container = getContainer();
83
		if (container != null)
84
			container.updateButtons();
85
	}
86
87
	private void addFilter() {
88
		fFilter = new AvailableFilter(fSelected, new LocaleLabelProvider());
89
		fAvailableListViewer.addFilter(fFilter);
90
		fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$
91
			public IStatus runInUIThread(IProgressMonitor monitor) {
92
				handleFilter();
93
				return Status.OK_STATUS;
94
			}
95
		};
96
		fFilterJob.setSystem(true);
97
	}
98
99
	private void handleFilter() {
100
		boolean changed = false;
101
		String newFilter;
102
		if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0)
103
			newFilter = AvailableFilter.WILDCARD;
104
		changed = fFilter.setPattern(newFilter);
105
		if (changed) {
106
			fAvailableListViewer.getTable().setRedraw(false);
107
			fAvailableListViewer.refresh();
108
			fAvailableListViewer.getTable().setRedraw(true);
109
			updateButtonEnablement(false, false);
110
		}
111
	}
112
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
115
	 */
116
	public void createControl(Composite parent) {
117
		Composite container = new Composite(parent, SWT.NONE);
118
		GridLayout layout = new GridLayout();
119
		layout.numColumns = 3;
120
		layout.makeColumnsEqualWidth = false;
121
		layout.horizontalSpacing = 5;
122
		layout.verticalSpacing = 20;
123
		container.setLayout(layout);
124
125
		createScrollArea(container);
126
		createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
127
		createButtonArea(container);
128
		createLocaleList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
129
		updateCount();
130
131
		// create container for buttons
132
		Composite buttonContainer = new Composite(container, SWT.NONE);
133
		buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create());
134
135
		addViewerListeners();
136
		addFilter();
137
138
		initialize();
139
		setControl(container);
140
		Dialog.applyDialogFont(container);
141
		PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE);
142
	}
143
144
	protected Composite createLocaleList(Composite parent) {
145
		Composite container = new Composite(parent, SWT.NONE);
146
		GridLayout layout = new GridLayout();
147
		layout.marginWidth = 0;
148
		layout.marginHeight = 0;
149
		container.setLayout(layout);
150
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
151
152
		Label label = new Label(container, SWT.NONE);
153
		label.setText(PDEUIMessages.InternationalizeWizard_LocalePage_internationalizeList);
154
155
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
156
		GridData gd = new GridData(GridData.FILL_BOTH);
157
		gd.widthHint = 225;
158
		table.setLayoutData(gd);
159
160
		fSelectedListViewer = new TableViewer(table);
161
		fSelectedListViewer.setLabelProvider(new LocaleLabelProvider());
162
		fSelectedListViewer.setContentProvider(new ContentProvider());
163
		fSelectedListViewer.setComparator(ListUtil.NAME_COMPARATOR);
164
		return container;
165
	}
166
167
	protected boolean isRefreshNeeded() {
168
		if (fRefreshNeeded) {
169
			fRefreshNeeded = false;
170
			return true;
171
		}
172
		if (fLocation == null) {
173
			return true;
174
		}
175
		return false;
176
	}
177
178
	protected void addLocale(Locale model, ArrayList selected) {
179
		if (!selected.contains(model)) {
180
			selected.add(model);
181
		}
182
	}
183
184
	public List getLocalesForInternationalization() {
185
		TableItem[] items = fSelectedListViewer.getTable().getItems();
186
		List result = new ArrayList();
187
		for (int i = 0; i < items.length; i++) {
188
			result.add(items[i].getData());
189
		}
190
		return result;
191
	}
192
193
	public void storeSettings() {
194
		IDialogSettings settings = getDialogSettings();
195
	}
196
197
	/* (non-Javadoc)
198
	 * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent)
199
	 */
200
	public void modelsChanged(IModelProviderEvent event) {
201
		fRefreshNeeded = true;
202
	}
203
204
	private void initialize() {
205
		updateButtonEnablement(true, true);
206
		setPageComplete(false);
207
	}
208
209
	private void addViewerListeners() {
210
		fAvailableListViewer.addDoubleClickListener(new IDoubleClickListener() {
211
			public void doubleClick(DoubleClickEvent event) {
212
				handleAdd();
213
			}
214
		});
215
216
		fSelectedListViewer.addDoubleClickListener(new IDoubleClickListener() {
217
			public void doubleClick(DoubleClickEvent event) {
218
				handleRemove();
219
			}
220
		});
221
222
		fAvailableListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
223
			public void selectionChanged(SelectionChangedEvent event) {
224
				if (!fBlockSelectionListeners)
225
					updateSelectionBasedEnablement(event.getSelection(), true);
226
			}
227
		});
228
229
		fSelectedListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
230
			public void selectionChanged(SelectionChangedEvent event) {
231
				if (!fBlockSelectionListeners)
232
					updateSelectionBasedEnablement(event.getSelection(), false);
233
			}
234
		});
235
236
		fFilterText.addModifyListener(new ModifyListener() {
237
			public void modifyText(ModifyEvent e) {
238
				fFilterJob.cancel();
239
				fFilterJob.schedule(200);
240
			}
241
		});
242
243
	}
244
245
	private Composite createAvailableList(Composite parent) {
246
		Composite container = new Composite(parent, SWT.NONE);
247
		GridLayout layout = new GridLayout();
248
		layout.marginWidth = 0;
249
		layout.marginHeight = 0;
250
		container.setLayout(layout);
251
		container.setLayoutData(new GridData());
252
253
		Label label = new Label(container, SWT.NONE);
254
		label.setText(PDEUIMessages.InternationalizeWizard_LocalePage_availableList);
255
256
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
257
		GridData gd = new GridData(GridData.FILL_BOTH);
258
		gd.heightHint = 200;
259
		gd.widthHint = 225;
260
		table.setLayoutData(gd);
261
262
		fAvailableListViewer = new TableViewer(table);
263
		fAvailableListViewer.setLabelProvider(new LocaleLabelProvider());
264
		fAvailableListViewer.setContentProvider(new ContentProvider());
265
		fAvailableListViewer.setInput(fInternationalizeModelTable);
266
		fAvailableListViewer.setComparator(ListUtil.NAME_COMPARATOR);
267
268
		return container;
269
	}
270
271
	private Composite createButtonArea(Composite parent) {
272
		ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
273
		GridLayout layout = new GridLayout();
274
		layout.marginWidth = layout.marginHeight = 0;
275
		comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
276
		Composite container = new Composite(comp, SWT.NONE);
277
		layout = new GridLayout();
278
		layout.marginWidth = 0;
279
		layout.marginTop = 50;
280
		container.setLayout(layout);
281
		GridData gd = new GridData(GridData.FILL_VERTICAL);
282
		gd.verticalIndent = 15;
283
		container.setLayoutData(gd);
284
285
		fAddButton = new Button(container, SWT.PUSH);
286
		fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add);
287
		fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
288
		fAddButton.addSelectionListener(new SelectionAdapter() {
289
			public void widgetSelected(SelectionEvent e) {
290
				handleAdd();
291
			}
292
		});
293
		SWTUtil.setButtonDimensionHint(fAddButton);
294
295
		fAddAllButton = new Button(container, SWT.PUSH);
296
		fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll);
297
		fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
298
		fAddAllButton.addSelectionListener(new SelectionAdapter() {
299
			public void widgetSelected(SelectionEvent e) {
300
				handleAddAll();
301
			}
302
		});
303
		SWTUtil.setButtonDimensionHint(fAddAllButton);
304
305
		fRemoveButton = new Button(container, SWT.PUSH);
306
		fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove);
307
		fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
308
		fRemoveButton.addSelectionListener(new SelectionAdapter() {
309
			public void widgetSelected(SelectionEvent e) {
310
				handleRemove();
311
			}
312
		});
313
		SWTUtil.setButtonDimensionHint(fRemoveButton);
314
315
		fRemoveAllButton = new Button(container, SWT.PUSH);
316
		fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll);
317
		fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
318
		fRemoveAllButton.addSelectionListener(new SelectionAdapter() {
319
			public void widgetSelected(SelectionEvent e) {
320
				handleRemoveAll();
321
			}
322
		});
323
		SWTUtil.setButtonDimensionHint(fRemoveAllButton);
324
325
		fCountLabel = new Label(container, SWT.NONE);
326
		fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
327
		comp.setContent(container);
328
		comp.setMinHeight(250);
329
		comp.setExpandHorizontal(true);
330
		comp.setExpandVertical(true);
331
		return container;
332
	}
333
334
	private Composite createScrollArea(Composite parent) {
335
		Group container = createFilterContainer(parent, PDEUIMessages.InternationalizeWizard_LocalePage_filter, PDEUIMessages.ImportWizard_DetailedPage_search);
336
		fFilterText = createFilterText(container, ""); //$NON-NLS-1$
337
		return container;
338
	}
339
340
	protected void refreshPage() {
341
		fSelectedListViewer.getTable().removeAll();
342
		fSelected = new HashMap();
343
		fAvailableListViewer.refresh();
344
		pageChanged();
345
	}
346
347
	protected void pageChanged() {
348
		pageChanged(false, false);
349
	}
350
351
	protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) {
352
		if (fSelectedListViewer.getTable().getItemCount() == 0) {
353
			setErrorMessage(PDEUIMessages.InternationalizeWizard_LocalePage_selectionError);
354
		} else {
355
			setErrorMessage(null);
356
		}
357
358
		updateCount();
359
		updateButtonEnablement(doAddEnablement, doRemoveEnablement);
360
		setPageComplete(fSelectedListViewer.getTable().getItemCount() > 0);
361
	}
362
363
	private void updateCount() {
364
		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()})));
365
		fCountLabel.getParent().layout();
366
	}
367
368
	private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
369
		int availableCount = fAvailableListViewer.getTable().getItemCount();
370
		int importCount = fSelectedListViewer.getTable().getItemCount();
371
372
		if (doAddEnablement)
373
			updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
374
		if (doRemoveEnablement)
375
			updateSelectionBasedEnablement(fSelectedListViewer.getSelection(), false);
376
377
		fAddAllButton.setEnabled(availableCount > 0);
378
		fRemoveAllButton.setEnabled(importCount > 0);
379
	}
380
381
	private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
382
		if (available)
383
			fAddButton.setEnabled(!theSelection.isEmpty());
384
		else
385
			fRemoveButton.setEnabled(!theSelection.isEmpty());
386
	}
387
388
	private void handleAdd() {
389
		IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
390
		if (ssel.size() > 0) {
391
			Table table = fAvailableListViewer.getTable();
392
			int index = table.getSelectionIndices()[0];
393
			Object[] selection = ssel.toArray();
394
			setBlockSelectionListeners(true);
395
			setRedraw(false);
396
			for (int i = 0; i < selection.length; i++) {
397
				doAdd(selection[i]);
398
			}
399
			setRedraw(true);
400
			setBlockSelectionListeners(false);
401
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
402
			pageChanged(true, false);
403
		}
404
	}
405
406
	private void handleAddAll() {
407
		TableItem[] items = fAvailableListViewer.getTable().getItems();
408
409
		ArrayList data = new ArrayList();
410
		for (int i = 0; i < items.length; i++) {
411
			data.add(items[i].getData());
412
		}
413
		if (data.size() > 0) {
414
			Object[] datas = data.toArray();
415
			setBlockSelectionListeners(true);
416
			setRedraw(false);
417
			for (int i = 0; i < datas.length; i++) {
418
				doAdd(datas[i]);
419
			}
420
			setRedraw(true);
421
			setBlockSelectionListeners(false);
422
			pageChanged(true, false);
423
		}
424
	}
425
426
	private void handleRemove() {
427
		IStructuredSelection ssel = (IStructuredSelection) fSelectedListViewer.getSelection();
428
		if (ssel.size() > 0) {
429
			Table table = fSelectedListViewer.getTable();
430
			int index = table.getSelectionIndices()[0];
431
			Object[] selection = ssel.toArray();
432
			setBlockSelectionListeners(true);
433
			setRedraw(false);
434
			for (int i = 0; i < selection.length; i++) {
435
				doRemove(selection[i]);
436
			}
437
			setRedraw(true);
438
			setBlockSelectionListeners(false);
439
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
440
			pageChanged(false, true);
441
		}
442
	}
443
444
	private void doAdd(Object o) {
445
		fInternationalizeModelTable.removeModel(o);
446
		fSelectedListViewer.add(o);
447
		fAvailableListViewer.remove(o);
448
		fSelected.put(o, null);
449
	}
450
451
	private void doRemove(Object o) {
452
		fInternationalizeModelTable.addModel(o);
453
		fSelected.remove(o);
454
		fSelectedListViewer.remove(o);
455
		fAvailableListViewer.add(o);
456
	}
457
458
	// used to prevent flicker during operations that move items between lists
459
	private void setRedraw(boolean redraw) {
460
		fAvailableListViewer.getTable().setRedraw(redraw);
461
		fSelectedListViewer.getTable().setRedraw(redraw);
462
	}
463
464
	private void handleRemoveAll() {
465
		TableItem[] items = fSelectedListViewer.getTable().getItems();
466
467
		ArrayList data = new ArrayList();
468
		for (int i = 0; i < items.length; i++) {
469
			data.add(items[i].getData());
470
		}
471
		if (data.size() > 0) {
472
			Object[] datas = data.toArray();
473
			setBlockSelectionListeners(true);
474
			setRedraw(false);
475
			for (int i = 0; i < datas.length; i++) {
476
				doRemove(datas[i]);
477
			}
478
			setRedraw(true);
479
			setBlockSelectionListeners(false);
480
			pageChanged(false, true);
481
		}
482
	}
483
484
	public void dispose() {
485
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
486
		PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this);
487
	}
488
489
	private void setBlockSelectionListeners(boolean blockSelectionListeners) {
490
		fBlockSelectionListeners = blockSelectionListeners;
491
	}
492
493
	public boolean isCurrentPage() {
494
		return super.isCurrentPage();
495
	}
496
497
	public boolean canFlipToNextPage() {
498
		return false;
499
	}
500
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java (+188 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
	private static final String STORE_SECTION = "InternationalizeWizard"; //$NON-NLS-1$
31
32
	private IAction action;
33
	private IStructuredSelection selection;
34
35
	//An intermediate selection passed to the ExternalizeStringsWizard
36
	private IStructuredSelection externalizeSelection;
37
38
	private InternationalizeWizardPluginPage page1;
39
	private InternationalizeWizardLocalePage page2;
40
41
	//Contains the list of plug-ins to be internationalized
42
	private InternationalizeModelTable fInternationalizePluginModelTable;
43
44
	//Contains the list of locales
45
	private InternationalizeModelTable fInternationalizeLocaleModelTable;
46
47
	public InternationalizeWizard(IAction action, InternationalizeModelTable pluginTable) {
48
		fInternationalizePluginModelTable = pluginTable;
49
		populateLocaleModelTable();
50
		IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings();
51
		setDialogSettings(getSettingsSection(masterSettings));
52
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_EXTSTR_WIZ);
53
		setWindowTitle(PDEUIMessages.InternationalizeWizard_title);
54
		this.action = action;
55
	}
56
57
	/**
58
	 * Populates the local InternationalizeModelTable with the list of all
59
	 * available locales
60
	 */
61
	private void populateLocaleModelTable() {
62
		fInternationalizeLocaleModelTable = new InternationalizeModelTable();
63
		Locale[] availableLocales = Locale.getAvailableLocales();
64
		for (int i = 0; i < availableLocales.length; i++) {
65
			fInternationalizeLocaleModelTable.addModel(availableLocales[i]);
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
		//Generate an NL fragment project for each of the selected plug-ins with the specified locales
122
		NLSFragmentGenerator fragmentGenerator = new NLSFragmentGenerator(page1.getTemplate(), getPluginModelsForInternationalization(), getLocalesForInternationalization(), this.getContainer(), page1.overwriteWithoutAsking());
123
		return fragmentGenerator.generate();
124
	}
125
126
	/**
127
	 * 
128
	 * @param currentPage
129
	 * @return the next wizard page
130
	 */
131
	public IWizardPage getNextPage(IWizardPage currentPage) {
132
		if (currentPage.equals(page1)) {
133
			ensurePluginsAreExternalized();
134
			return page2;
135
		}
136
		return null;
137
	}
138
139
	/**
140
	 * 
141
	 * @param currentPage
142
	 * @return the previous wizard page
143
	 */
144
	public IWizardPage getPreviousPage(IWizardPage currentPage) {
145
		if (currentPage.equals(page2)) {
146
			return page1;
147
		}
148
		return null;
149
	}
150
151
	public boolean canFinish() {
152
		return getPluginModelsForInternationalization().size() > 0 && getLocalesForInternationalization().size() > 0;
153
	}
154
155
	/**
156
	 * Checks whether or not the selected plug-ins are already externalized. This
157
	 * method invokes the ExternalizeStringsWizard on the selected plug-ins.
158
	 */
159
	public void ensurePluginsAreExternalized() {
160
		GetNonExternalizedStringsAction externalize = new GetNonExternalizedStringsAction();
161
162
		List projects = new ArrayList();
163
		List pluginModels = getPluginModelsForInternationalization();
164
		selection = new StructuredSelection(pluginModels); //Save the plug-ins selected for internationalization in a StructuredSelection
165
166
		for (Iterator it = pluginModels.iterator(); it.hasNext();) {
167
			IPluginModelBase pluginModel = (IPluginModelBase) it.next();
168
			//Externalize only workspace plug-ins since external plug-ins are already externalized
169
			if (!(pluginModel instanceof ExternalPluginModel)) {
170
				IProject project = pluginModel.getUnderlyingResource().getProject();
171
				projects.add(project);
172
			}
173
		}
174
175
		//Set the selection for the non-externalized plug-ins that 
176
		//should be passed to the ExternalizeStringsWizard
177
		externalizeSelection = new StructuredSelection(projects);
178
179
		externalize.selectionChanged(action, externalizeSelection);
180
		externalize.setExternalizeSelectedPluginsOnly(true);
181
		externalize.setSkipMessageDialog(true);
182
		externalize.run(action);
183
	}
184
185
	public boolean performCancel() {
186
		return super.performCancel();
187
	}
188
}
(-)src/org/eclipse/pde/internal/ui/nls/NLSFragmentGenerator.java (+268 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.io.*;
4
import java.lang.reflect.InvocationTargetException;
5
import java.util.*;
6
import java.util.zip.ZipEntry;
7
import java.util.zip.ZipFile;
8
import org.eclipse.core.resources.*;
9
import org.eclipse.core.runtime.*;
10
import org.eclipse.jface.dialogs.MessageDialog;
11
import org.eclipse.jface.wizard.IWizardContainer;
12
import org.eclipse.osgi.util.NLS;
13
import org.eclipse.pde.core.plugin.IPluginModelBase;
14
import org.eclipse.pde.internal.core.TargetPlatformHelper;
15
import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase;
16
import org.eclipse.pde.internal.ui.PDEPlugin;
17
import org.eclipse.pde.internal.ui.PDEUIMessages;
18
import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
19
import org.eclipse.pde.internal.ui.wizards.plugin.FragmentFieldData;
20
import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationOperation;
21
22
/**
23
 * 
24
 * Generates the fragment projects for the list of selected plug-ins.
25
 * Each fragment contains a series of properties files specific to the locales
26
 * the user selected. For example plugin_fr.properties for the french locale
27
 * selection. The generated locale-specific properties files contain the same
28
 * key-value pairs as the properties file of the initial plug-in.
29
 * 
30
 * @author Team Azure
31
 *
32
 */
33
public class NLSFragmentGenerator {
34
35
	public static final String PLUGIN_NAME_MACRO = "${plugin_name}"; //$NON-NLS-1$
36
37
	private static final double LATEST_ECLIPSE_VERSION = 3.4;
38
39
	private static final String ZERO = "0"; //$NON-NLS-1$
40
	private static final String PERIOD = "."; //$NON-NLS-1$
41
	private static final String MIN_MINOR = ZERO; //$NON-NLS-1$
42
	private static final String MAX_MINOR = "9"; //$NON-NLS-1$
43
	private static final String LEFT_SQUARE_BRACKET = "["; //$NON-NLS-1$
44
	private static final String RIGHT_PARENTHESIS = ")"; //$NON-NLS-1$
45
	private static final String DEFAULT_VERSION = "1.0.0"; //$NON-NLS-1$
46
	private static final String VERSION_FORMAT_WITH_QUALIFIER = "\\d+\\.\\d+\\.\\d+\\..+"; //$NON-NLS-1$
47
	private static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$
48
	private static final String LOCALE_PROPERTIES_FILE_PREFIX = "plugin_"; //$NON-NLS-1$
49
	private static final String JAR_SUFFIX = ".jar"; //$NON-NLS-1$
50
	private static final String PROPERTIES_FILE_NAME = "plugin.properties"; //$NON-NLS-1$
51
	private static final String PATH_SEPERATOR = "\\"; //$NON-NLS-1$
52
53
	private FragmentFieldData fFragmentData;
54
	private IProjectProvider fProjectProvider;
55
	private IWizardContainer container;
56
	private String template;
57
58
	private final List plugins;
59
60
	private final List locales;
61
62
	private final boolean overwriteWithoutAsking;
63
64
	public NLSFragmentGenerator(String template, List plugins, List locales, IWizardContainer container, boolean overwriteWithoutAsking) {
65
		this.plugins = plugins;
66
		this.locales = locales;
67
		this.container = container;
68
		this.template = template;
69
		this.overwriteWithoutAsking = overwriteWithoutAsking;
70
	}
71
72
	public boolean generate() {
73
		return internationalizePlugins(plugins, locales);
74
	}
75
76
	/**
77
	 * Creates an NL fragment project along with the locale specific properties
78
	 * files.
79
	 */
80
	private boolean internationalizePlugins(List plugins, List locales) {
81
		for (Iterator it = plugins.iterator(); it.hasNext();) {
82
			IPluginModelBase plugin = (IPluginModelBase) it.next();
83
			if (!createNLFragment(plugin))
84
				return false;
85
86
			IProject currentFragmentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(pluginName(plugin));
87
88
			for (Iterator iter = locales.iterator(); iter.hasNext();) {
89
				Locale locale = (Locale) iter.next();
90
				createLocaleSpecificPropertiesFile(currentFragmentProject, plugin, locale);
91
			}
92
		}
93
94
		return true;
95
	}
96
97
	/**
98
	 * Creates a fragment project for the specified plug-in and populates
99
	 * the field data.
100
	 * @param plugin
101
	 */
102
	private boolean createNLFragment(IPluginModelBase plugin) {
103
		final String name = pluginName(plugin);
104
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
105
		if (!overwriteWithoutAsking && project.exists()) {
106
			boolean overwrite = MessageDialog.openConfirm(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle, NLS.bind(PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage, name));
107
			if (!overwrite)
108
				return false;
109
		}
110
111
		if (project.exists()) {
112
			try {
113
				project.delete(true, new NullProgressMonitor());
114
			} catch (CoreException e1) {
115
				// TODO Auto-generated catch block
116
				e1.printStackTrace();
117
			}
118
		}
119
120
		fFragmentData = new FragmentFieldData();
121
122
		populateFieldData(plugin);
123
124
		fProjectProvider = new IProjectProvider() {
125
			public String getProjectName() {
126
				return name;
127
			}
128
129
			public IProject getProject() {
130
				return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
131
			}
132
133
			public IPath getLocationPath() {
134
				return new Path(Platform.getLocation().toOSString());
135
			}
136
		};
137
138
		try {
139
			container.run(false, true, new NewProjectCreationOperation(fFragmentData, fProjectProvider, null));
140
		} catch (InvocationTargetException e) {
141
			e.printStackTrace();
142
		} catch (InterruptedException e) {
143
			e.printStackTrace();
144
		}
145
		return true;
146
	}
147
148
	private String pluginName(IPluginModelBase plugin) {
149
		return template.replace(PLUGIN_NAME_MACRO, plugin.getPluginBase().getId());
150
	}
151
152
	/**
153
	 * The fields are populated based on the plug-in attributes. Some fields
154
	 * are set to their default values.
155
	 */
156
	private void populateFieldData(IPluginModelBase plugin) {
157
158
		fFragmentData.setId(pluginName(plugin));
159
		fFragmentData.setVersion(DEFAULT_VERSION);
160
		fFragmentData.setMatch(0);
161
162
		fFragmentData.setPluginId(plugin.getPluginBase().getId());
163
		fFragmentData.setPluginVersion(incrementRelease(plugin.getPluginBase().getVersion()));
164
		fFragmentData.setName(pluginName(plugin) + " Fragment"); //$NON-NLS-1$
165
		fFragmentData.setProvider(""); //$NON-NLS-1$
166
		fFragmentData.setSimple(true);
167
168
		if (!(plugin instanceof ExternalPluginModelBase)) {
169
			fFragmentData.setSourceFolderName("src"); //$NON-NLS-1$
170
			fFragmentData.setOutputFolderName("bin"); //$NON-NLS-1$
171
		}
172
173
		fFragmentData.setLegacy(false);
174
		fFragmentData.setTargetVersion(Double.toString(ensureTargetVersionCompatibility(TargetPlatformHelper.getTargetVersion())));
175
		fFragmentData.setHasBundleStructure(true);
176
		fFragmentData.setOSGiFramework(null);
177
		fFragmentData.setWorkingSets(null);
178
	}
179
180
	/**
181
	 * Adjusts the plug-in's version to reflect the required
182
	 * fragment-host bundle-version range. For example, 
183
	 * fragment-host's bundle-version range would be: "[1.0.0, 1.1.0)" 
184
	 * if the host's version is 1.0.0
185
	 * @param oldVersion
186
	 * @return adjusted plug-in version
187
	 */
188
	private String incrementRelease(String oldVersion) {
189
		if (oldVersion.matches(VERSION_FORMAT_WITH_QUALIFIER)) {
190
			oldVersion = oldVersion.substring(0, oldVersion.lastIndexOf(PERIOD));
191
		}
192
193
		String newVersion = LEFT_SQUARE_BRACKET + oldVersion + ',';
194
		String oldMinor = oldVersion.substring(oldVersion.indexOf(PERIOD) + 1, oldVersion.lastIndexOf(PERIOD));
195
196
		if (oldMinor.compareTo(MAX_MINOR) == 0) {
197
			String major = Integer.toString(Integer.parseInt(oldVersion.substring(0, oldVersion.indexOf(PERIOD))) + 1);
198
			newVersion += major + PERIOD + MIN_MINOR + PERIOD + ZERO + RIGHT_PARENTHESIS;
199
		} else {
200
			String major = oldVersion.substring(0, oldVersion.indexOf(PERIOD));
201
			String newMinor = Integer.toString(Integer.parseInt(oldMinor) + 1);
202
			newVersion += major + PERIOD + newMinor + PERIOD + ZERO + RIGHT_PARENTHESIS;
203
		}
204
205
		return newVersion;
206
	}
207
208
	/**
209
	 * Creates a locale specific properties file within the fragment project 
210
	 * based on the content of the host plug-in's properties file.
211
	 * @param fragmentProject
212
	 * @param locale
213
	 */
214
	private void createLocaleSpecificPropertiesFile(IProject fragmentProject, IPluginModelBase plugin, Locale locale) {
215
		IFile localeProperties = fragmentProject.getFile(LOCALE_PROPERTIES_FILE_PREFIX + locale + PROPERTIES_FILE_EXTENSION);
216
217
		//Case 1: External plug-in
218
		if (plugin instanceof ExternalPluginModelBase) {
219
			String installLocation = plugin.getInstallLocation();
220
			//Case 1a: External plug-in is a jar file
221
			if (installLocation.endsWith(JAR_SUFFIX)) {
222
				try {
223
					ZipFile zf = new ZipFile(installLocation);
224
					ZipEntry zfe = zf.getEntry(PROPERTIES_FILE_NAME);
225
					InputStream is = zf.getInputStream(zfe);
226
					localeProperties.create(is, false, null);
227
				} catch (Exception e) {
228
					e.printStackTrace();
229
				}
230
			}
231
			//Case 1b: External plug-in has a folder structure
232
			else {
233
				File propertiesFileLocation = new File(installLocation + PATH_SEPERATOR + PROPERTIES_FILE_NAME);
234
				try {
235
					FileInputStream is = new FileInputStream(propertiesFileLocation);
236
					localeProperties.create(is, false, null);
237
				} catch (Exception e) {
238
					e.printStackTrace();
239
				}
240
			}
241
		}
242
		//Case 2: Workspace plug-in
243
		else {
244
			IFile pluginProperties = plugin.getUnderlyingResource().getProject().getFile(PROPERTIES_FILE_NAME);
245
246
			if (!localeProperties.exists()) {
247
				try {
248
					pluginProperties.copy(localeProperties.getFullPath(), false, null);
249
250
				} catch (Exception e) {
251
					e.printStackTrace();
252
				}
253
			}
254
		}
255
	}
256
257
	/**
258
	 * Ensures that the target version is compatible.
259
	 * @param targetVersion
260
	 * @return target version
261
	 */
262
	private double ensureTargetVersionCompatibility(double targetVersion) {
263
		if (targetVersion < 3.0) {
264
			return LATEST_ECLIPSE_VERSION;
265
		}
266
		return targetVersion;
267
	}
268
}
(-)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 (+608 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 org.eclipse.core.runtime.*;
9
import org.eclipse.jface.dialogs.Dialog;
10
import org.eclipse.jface.dialogs.IDialogSettings;
11
import org.eclipse.jface.viewers.*;
12
import org.eclipse.jface.wizard.IWizardContainer;
13
import org.eclipse.osgi.util.NLS;
14
import org.eclipse.pde.core.IModelProviderEvent;
15
import org.eclipse.pde.core.IModelProviderListener;
16
import org.eclipse.pde.core.plugin.*;
17
import org.eclipse.pde.internal.core.ClasspathUtilCore;
18
import org.eclipse.pde.internal.core.PDECore;
19
import org.eclipse.pde.internal.ui.*;
20
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
21
import org.eclipse.pde.internal.ui.util.SWTUtil;
22
import org.eclipse.pde.internal.ui.wizards.ListUtil;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.custom.ScrolledComposite;
25
import org.eclipse.swt.events.*;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.*;
29
import org.eclipse.ui.PlatformUI;
30
import org.eclipse.ui.progress.WorkbenchJob;
31
32
/**
33
 * The first page of the InternationalizeWizard. This page allows the user to 
34
 * select the desired plug-ins for internationalization. These could be plug-ins
35
 * in the user's workspace or external ones.
36
 * 
37
 * @author Team Azure
38
 *
39
 */
40
public class InternationalizeWizardPluginPage extends InternationalizationWizardPage implements IModelProviderListener {
41
42
	public static final String PAGE_NAME = "InternationalizeWizardPluginPage"; //$NON-NLS-1$
43
44
	protected IPluginModelBase[] fModels = new IPluginModelBase[0];
45
46
	private boolean fRefreshNeeded = true;
47
48
	private Label fCountLabel; //Displays "x out of y selected"
49
50
	private TableViewer fAvailableViewer; //All available plug-ins
51
	protected TableViewer fSelectedViewer; //Selected plug-ins
52
53
	private WorkbenchJob fFilterJob;
54
	private Text fFilterText;
55
	private Text fTemplateText;
56
	private AvailableFilter fFilter;
57
58
	// Used to track the selection in a HashMap so as to filter
59
	// selected items out of the available item list
60
	private final Map fSelected = new HashMap();
61
62
	// Used to block the selection listeners from updating button enablement
63
	// when programatically removing items
64
	private boolean fBlockSelectionListeners;
65
	private Button fAddButton;
66
	private Button fAddAllButton;
67
	private Button fRemoveButton;
68
	private Button fRemoveAllButton;
69
70
	// Used to store the plug-ins
71
	private InternationalizeModelTable fInternationalizeModelTable;
72
73
	private Button overwriteOption;
74
75
	private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
76
		/**
77
		 * @return the list of available non-selected plug-ins
78
		 */
79
		public Object[] getElements(Object parent) {
80
			return fInternationalizeModelTable.getModels();
81
		}
82
	}
83
84
	private class SelectedContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
85
		/**
86
		 * @return the list of selected plug-ins
87
		 */
88
		public Object[] getElements(Object parent) {
89
			return fInternationalizeModelTable.getPreSelected();
90
		}
91
	}
92
93
	public InternationalizeWizardPluginPage(InternationalizeModelTable modelTable, String pageName) {
94
95
		super(pageName);
96
		setTitle(PDEUIMessages.InternationalizeWizard_PluginPage_pageTitle);
97
		setDescription(PDEUIMessages.InternationalizeWizard_PluginPage_pageDescription);
98
99
		PDEPlugin.getDefault().getLabelProvider().connect(this);
100
		PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this);
101
102
		fInternationalizeModelTable = modelTable;
103
104
		IWizardContainer container = getContainer();
105
		if (container != null)
106
			container.updateButtons();
107
	}
108
109
	/**
110
	 * Adds a filter to the list of available plug-ins
111
	 */
112
	private void addFilter() {
113
		fFilter = new AvailableFilter(fSelected, PDEPlugin.getDefault().getLabelProvider());
114
		fAvailableViewer.addFilter(fFilter);
115
		fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$
116
			public IStatus runInUIThread(IProgressMonitor monitor) {
117
				handleFilter();
118
				return Status.OK_STATUS;
119
			}
120
		};
121
		fFilterJob.setSystem(true);
122
	}
123
124
	/**
125
	 * Handles changes to the list based on changes to the text field.
126
	 */
127
	private void handleFilter() {
128
		boolean changed = false;
129
		String newFilter;
130
		if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0)
131
			newFilter = AvailableFilter.WILDCARD;
132
		changed = fFilter.setPattern(newFilter);
133
		if (changed) {
134
			fAvailableViewer.getTable().setRedraw(false);
135
			fAvailableViewer.refresh();
136
			fAvailableViewer.getTable().setRedraw(true);
137
			updateButtonEnablement(false, false);
138
		}
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
143
	 */
144
	public void createControl(Composite parent) {
145
		Composite container = new Composite(parent, SWT.NONE);
146
		GridLayout layout = new GridLayout();
147
		layout.numColumns = 3;
148
		layout.makeColumnsEqualWidth = false;
149
		layout.horizontalSpacing = 5;
150
		layout.verticalSpacing = 20;
151
		container.setLayout(layout);
152
153
		createScrollArea(container);
154
		createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
155
		createButtonArea(container);
156
		createInternationalizeList(container).setLayoutData(new GridData(GridData.FILL_BOTH));
157
		updateCount();
158
159
		createTemplateField(container);
160
		overwriteOption = new Button(container, SWT.CHECK);
161
		overwriteOption.setText(PDEUIMessages.InternationalizeWizard_PluginPage_overwriteWithoutAsking);
162
163
		addViewerListeners();
164
		addFilter();
165
166
		initialize();
167
		setControl(container);
168
		Dialog.applyDialogFont(container);
169
		PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE);
170
	}
171
172
	/**
173
	 * @param parent
174
	 * @return the container holding the available plug-ins list
175
	 */
176
	private Composite createAvailableList(Composite parent) {
177
		Composite container = createViewerContainer(parent, PDEUIMessages.InternationalizeWizard_PluginPage_availableList);
178
		fAvailableViewer = createTableViewer(container, new ContentProvider(), PDECore.getDefault().getModelManager());
179
		return container;
180
	}
181
182
	protected Composite createInternationalizeList(Composite parent) {
183
		Composite container = createViewerContainer(parent, PDEUIMessages.InternationalizeWizard_PluginPage_internationalizeList);
184
		fSelectedViewer = createTableViewer(container, new SelectedContentProvider(), PDECore.getDefault().getModelManager().getExternalModelManager());
185
		return container;
186
	}
187
188
	private Composite createViewerContainer(Composite parent, String message) {
189
		Composite container = new Composite(parent, SWT.NONE);
190
		GridLayout layout = new GridLayout();
191
		layout.marginWidth = 0;
192
		layout.marginHeight = 0;
193
		container.setLayout(layout);
194
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
195
196
		Label label = new Label(container, SWT.NONE);
197
		label.setText(message);
198
		return container;
199
	}
200
201
	private static TableViewer createTableViewer(Composite container, IContentProvider provider, Object manager) {
202
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
203
		GridData gd = new GridData(GridData.FILL_BOTH);
204
		gd.heightHint = 200;
205
		gd.widthHint = 225;
206
		table.setLayoutData(gd);
207
208
		TableViewer viewer = new TableViewer(table);
209
		viewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
210
		viewer.setContentProvider(provider);
211
		viewer.setInput(manager);
212
		viewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
213
		return viewer;
214
	}
215
216
	protected boolean isRefreshNeeded() {
217
		if (fRefreshNeeded) {
218
			fRefreshNeeded = false;
219
			return true;
220
		}
221
222
		return false;
223
	}
224
225
	private IPluginModelBase findModel(String id) {
226
		for (int i = 0; i < fModels.length; i++) {
227
			String modelId = fModels[i].getPluginBase().getId();
228
			if (modelId != null && modelId.equals(id))
229
				return fModels[i];
230
		}
231
		return null;
232
	}
233
234
	private IFragmentModel[] findFragments(IPlugin plugin) {
235
		ArrayList result = new ArrayList();
236
		for (int i = 0; i < fModels.length; i++) {
237
			if (fModels[i] instanceof IFragmentModel) {
238
				IFragment fragment = ((IFragmentModel) fModels[i]).getFragment();
239
				if (plugin.getId().equalsIgnoreCase(fragment.getPluginId())) {
240
					result.add(fModels[i]);
241
				}
242
			}
243
		}
244
		return (IFragmentModel[]) result.toArray(new IFragmentModel[result.size()]);
245
	}
246
247
	protected void addPluginAndDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) {
248
249
		boolean containsVariable = false;
250
		if (!selected.contains(model)) {
251
			selected.add(model);
252
			boolean hasextensibleAPI = ClasspathUtilCore.hasExtensibleAPI(model);
253
			if (!addFragments && !hasextensibleAPI && model instanceof IPluginModel) {
254
				IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
255
				for (int i = 0; i < libraries.length; i++) {
256
					if (ClasspathUtilCore.containsVariables(libraries[i].getName())) {
257
						containsVariable = true;
258
						break;
259
					}
260
				}
261
			}
262
			addDependencies(model, selected, addFragments || containsVariable || hasextensibleAPI);
263
		}
264
	}
265
266
	protected void addDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) {
267
268
		IPluginImport[] required = model.getPluginBase().getImports();
269
		if (required.length > 0) {
270
			for (int i = 0; i < required.length; i++) {
271
				IPluginModelBase found = findModel(required[i].getId());
272
				if (found != null) {
273
					addPluginAndDependencies(found, selected, addFragments);
274
				}
275
			}
276
		}
277
278
		if (addFragments) {
279
			if (model instanceof IPluginModel) {
280
				IFragmentModel[] fragments = findFragments(((IPluginModel) model).getPlugin());
281
				for (int i = 0; i < fragments.length; i++) {
282
					addPluginAndDependencies(fragments[i], selected, addFragments);
283
				}
284
			} else {
285
				IFragment fragment = ((IFragmentModel) model).getFragment();
286
				IPluginModelBase found = findModel(fragment.getPluginId());
287
				if (found != null) {
288
					addPluginAndDependencies(found, selected, addFragments);
289
				}
290
			}
291
		}
292
	}
293
294
	public List getModelsToInternationalize() {
295
		TableItem[] items = fSelectedViewer.getTable().getItems();
296
		List result = new ArrayList();
297
		for (int i = 0; i < items.length; i++) {
298
			result.add(items[i].getData());
299
		}
300
		return result;
301
	}
302
303
	public void storeSettings() {
304
		IDialogSettings settings = getDialogSettings();
305
	}
306
307
	/* (non-Javadoc)
308
	 * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent)
309
	 */
310
	public void modelsChanged(IModelProviderEvent event) {
311
		fRefreshNeeded = true;
312
	}
313
314
	private void initialize() {
315
		updateButtonEnablement(true, true);
316
		setPageComplete(false);
317
	}
318
319
	private void addViewerListeners() {
320
		fAvailableViewer.addDoubleClickListener(new IDoubleClickListener() {
321
			public void doubleClick(DoubleClickEvent event) {
322
				handleAdd();
323
			}
324
		});
325
326
		fSelectedViewer.addDoubleClickListener(new IDoubleClickListener() {
327
			public void doubleClick(DoubleClickEvent event) {
328
				handleRemove();
329
			}
330
		});
331
332
		fAvailableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
333
			public void selectionChanged(SelectionChangedEvent event) {
334
				if (!fBlockSelectionListeners)
335
					updateSelectionBasedEnablement(event.getSelection(), true);
336
			}
337
		});
338
339
		fSelectedViewer.addSelectionChangedListener(new ISelectionChangedListener() {
340
			public void selectionChanged(SelectionChangedEvent event) {
341
				if (!fBlockSelectionListeners)
342
					updateSelectionBasedEnablement(event.getSelection(), false);
343
			}
344
		});
345
346
		fFilterText.addModifyListener(new ModifyListener() {
347
			public void modifyText(ModifyEvent e) {
348
				fFilterJob.cancel();
349
				fFilterJob.schedule(200);
350
			}
351
		});
352
353
	}
354
355
	private Composite createButtonArea(Composite parent) {
356
		ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
357
		GridLayout layout = new GridLayout();
358
		layout.marginWidth = layout.marginHeight = 0;
359
		comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
360
		Composite container = new Composite(comp, SWT.NONE);
361
		layout = new GridLayout();
362
		layout.marginWidth = 0;
363
		layout.marginTop = 50;
364
		container.setLayout(layout);
365
		GridData gd = new GridData(GridData.FILL_VERTICAL);
366
		gd.verticalIndent = 15;
367
		container.setLayoutData(gd);
368
369
		fAddButton = new Button(container, SWT.PUSH);
370
		fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add);
371
		fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
372
		fAddButton.addSelectionListener(new SelectionAdapter() {
373
			public void widgetSelected(SelectionEvent e) {
374
				handleAdd();
375
			}
376
		});
377
		SWTUtil.setButtonDimensionHint(fAddButton);
378
379
		fAddAllButton = new Button(container, SWT.PUSH);
380
		fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll);
381
		fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
382
		fAddAllButton.addSelectionListener(new SelectionAdapter() {
383
			public void widgetSelected(SelectionEvent e) {
384
				handleAddAll();
385
			}
386
		});
387
		SWTUtil.setButtonDimensionHint(fAddAllButton);
388
389
		fRemoveButton = new Button(container, SWT.PUSH);
390
		fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove);
391
		fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
392
		fRemoveButton.addSelectionListener(new SelectionAdapter() {
393
			public void widgetSelected(SelectionEvent e) {
394
				handleRemove();
395
			}
396
		});
397
		SWTUtil.setButtonDimensionHint(fRemoveButton);
398
399
		fRemoveAllButton = new Button(container, SWT.PUSH);
400
		fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll);
401
		fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
402
		fRemoveAllButton.addSelectionListener(new SelectionAdapter() {
403
			public void widgetSelected(SelectionEvent e) {
404
				handleRemoveAll();
405
			}
406
		});
407
		SWTUtil.setButtonDimensionHint(fRemoveAllButton);
408
409
		fCountLabel = new Label(container, SWT.NONE);
410
		fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
411
		comp.setContent(container);
412
		comp.setMinHeight(250);
413
		comp.setExpandHorizontal(true);
414
		comp.setExpandVertical(true);
415
		return container;
416
	}
417
418
	private Composite createTemplateField(Composite parent) {
419
		Group container = createFilterContainer(parent, PDEUIMessages.InternationalizeWizard_PluginPage_template, PDEUIMessages.InternationalizeWizard_PluginPage_templateLabel);
420
		fTemplateText = createFilterText(container, NLSFragmentGenerator.PLUGIN_NAME_MACRO + ".nl1");
421
		fTemplateText.addModifyListener(new ModifyListener() {
422
			public void modifyText(ModifyEvent e) {
423
				pageChanged();
424
			}
425
		});
426
		return container;
427
	}
428
429
	private Composite createScrollArea(Composite parent) {
430
		Group container = createFilterContainer(parent, PDEUIMessages.InternationalizeWizard_PluginPage_filter, PDEUIMessages.ImportWizard_DetailedPage_search);
431
		fFilterText = createFilterText(container, ""); //$NON-NLS-1$
432
		return container;
433
	}
434
435
	protected void refreshPage() {
436
		fSelectedViewer.getTable().removeAll();
437
		fSelected.clear();
438
		fAvailableViewer.refresh();
439
		pageChanged();
440
	}
441
442
	protected void pageChanged() {
443
		pageChanged(false, false);
444
	}
445
446
	protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) {
447
		if (fTemplateText.getText().length() == 0) {
448
			setErrorMessage(PDEUIMessages.InternationalizeWizard_PluginPage_templateError);
449
		} else if (fSelectedViewer.getTable().getItemCount() == 0) {
450
			setErrorMessage(PDEUIMessages.InternationalizeWizard_PluginPage_selectionError);
451
		} else {
452
			setErrorMessage(null);
453
		}
454
455
		updateCount();
456
		updateButtonEnablement(doAddEnablement, doRemoveEnablement);
457
		setPageComplete(fSelectedViewer.getTable().getItemCount() > 0);
458
	}
459
460
	private void updateCount() {
461
		fCountLabel.setText(NLS.bind(PDEUIMessages.ImportWizard_DetailedPage_count, (new String[] {new Integer(fSelectedViewer.getTable().getItemCount()).toString(), new Integer(fAvailableViewer.getTable().getItemCount() + fSelectedViewer.getTable().getItemCount()).toString()})));
462
		fCountLabel.getParent().layout();
463
	}
464
465
	private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
466
		int availableCount = fAvailableViewer.getTable().getItemCount();
467
		int importCount = fSelectedViewer.getTable().getItemCount();
468
469
		if (doAddEnablement)
470
			updateSelectionBasedEnablement(fAvailableViewer.getSelection(), true);
471
		if (doRemoveEnablement)
472
			updateSelectionBasedEnablement(fSelectedViewer.getSelection(), false);
473
474
		fAddAllButton.setEnabled(availableCount > 0);
475
		fRemoveAllButton.setEnabled(importCount > 0);
476
	}
477
478
	private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
479
		if (available)
480
			fAddButton.setEnabled(!theSelection.isEmpty());
481
		else
482
			fRemoveButton.setEnabled(!theSelection.isEmpty());
483
	}
484
485
	private void handleAdd() {
486
		IStructuredSelection ssel = (IStructuredSelection) fAvailableViewer.getSelection();
487
		if (ssel.size() > 0) {
488
			Table table = fAvailableViewer.getTable();
489
			int index = table.getSelectionIndices()[0];
490
			Object[] selection = ssel.toArray();
491
			setBlockSelectionListeners(true);
492
			setRedraw(false);
493
			for (int i = 0; i < selection.length; i++) {
494
				doAdd(selection[i]);
495
			}
496
			setRedraw(true);
497
			setBlockSelectionListeners(false);
498
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
499
			pageChanged(true, false);
500
		}
501
	}
502
503
	private void handleAddAll() {
504
		TableItem[] items = fAvailableViewer.getTable().getItems();
505
506
		ArrayList data = new ArrayList();
507
		for (int i = 0; i < items.length; i++) {
508
			data.add(items[i].getData());
509
		}
510
		if (data.size() > 0) {
511
			Object[] datas = data.toArray();
512
			setBlockSelectionListeners(true);
513
			setRedraw(false);
514
			for (int i = 0; i < datas.length; i++) {
515
				doAdd(datas[i]);
516
			}
517
			setRedraw(true);
518
			setBlockSelectionListeners(false);
519
			pageChanged(true, false);
520
		}
521
	}
522
523
	private void handleRemove() {
524
		IStructuredSelection ssel = (IStructuredSelection) fSelectedViewer.getSelection();
525
		if (ssel.size() > 0) {
526
			Table table = fSelectedViewer.getTable();
527
			int index = table.getSelectionIndices()[0];
528
			Object[] selection = ssel.toArray();
529
			setBlockSelectionListeners(true);
530
			setRedraw(false);
531
			for (int i = 0; i < selection.length; i++) {
532
				doRemove(selection[i]);
533
			}
534
			setRedraw(true);
535
			setBlockSelectionListeners(false);
536
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
537
			pageChanged(false, true);
538
		}
539
	}
540
541
	private void doAdd(Object o) {
542
		fInternationalizeModelTable.removeModel(o);
543
		fSelectedViewer.add(o);
544
		fAvailableViewer.remove(o);
545
		fSelected.put(o, null);
546
	}
547
548
	private void doRemove(Object o) {
549
		fInternationalizeModelTable.addModel(o);
550
		fSelected.remove(o);
551
		fSelectedViewer.remove(o);
552
		fAvailableViewer.add(o);
553
	}
554
555
	// used to prevent flicker during operations that move items between lists
556
	private void setRedraw(boolean redraw) {
557
		fAvailableViewer.getTable().setRedraw(redraw);
558
		fSelectedViewer.getTable().setRedraw(redraw);
559
	}
560
561
	private void handleRemoveAll() {
562
		TableItem[] items = fSelectedViewer.getTable().getItems();
563
564
		ArrayList data = new ArrayList();
565
		for (int i = 0; i < items.length; i++) {
566
			data.add(items[i].getData());
567
		}
568
		if (data.size() > 0) {
569
			Object[] datas = data.toArray();
570
			setBlockSelectionListeners(true);
571
			setRedraw(false);
572
			for (int i = 0; i < datas.length; i++) {
573
				doRemove(datas[i]);
574
			}
575
			setRedraw(true);
576
			setBlockSelectionListeners(false);
577
			pageChanged(false, true);
578
		}
579
	}
580
581
	public void dispose() {
582
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
583
		PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this);
584
	}
585
586
	private void setBlockSelectionListeners(boolean blockSelectionListeners) {
587
		fBlockSelectionListeners = blockSelectionListeners;
588
	}
589
590
	public boolean isCurrentPage() {
591
		return super.isCurrentPage();
592
	}
593
594
	public boolean canFlipToNextPage() {
595
		if (fSelectedViewer.getTable().getItems().length > 0 && getTemplate().length() > 0) {
596
			return true;
597
		}
598
		return false;
599
	}
600
601
	public String getTemplate() {
602
		return fTemplateText.getText();
603
	}
604
605
	public boolean overwriteWithoutAsking() {
606
		return overwriteOption.getSelection();
607
	}
608
}
(-)src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java (+92 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.nls;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
/**
7
 * 
8
 * Stores the list of BundlePluginModels and ExternalPluginModels to be passed to the
9
 * InternationalizeWizard. This class could also used to populate the list of locales
10
 * to which plug-ins will be internationalized.
11
 * 
12
 * @author Team Azure
13
 *
14
 */
15
public class InternationalizeModelTable {
16
	private List fModels;
17
	private List fPreSelected; //Models preselected by the user
18
19
	public InternationalizeModelTable() {
20
		fModels = new ArrayList();
21
		fPreSelected = new ArrayList();
22
	}
23
24
	/**
25
	 * Adds the model to the model table. Takes into consideration the specified
26
	 * selection.
27
	 * @param model
28
	 * @param selected
29
	 */
30
	public void addToModelTable(Object model, boolean selected) {
31
		if (selected)
32
			fPreSelected.add(model);
33
		else
34
			fModels.add(model);
35
	}
36
37
	/**
38
	 * Adds the model to the model table.
39
	 * @param model
40
	 */
41
	public void addModel(Object model) {
42
		fModels.add(model);
43
	}
44
45
	/**
46
	 * Removes the specified model from the model table.
47
	 * @param model
48
	 */
49
	public void removeModel(Object model) {
50
		fModels.remove(model);
51
	}
52
53
	/**
54
	 * 
55
	 * @return the number of models in the table
56
	 */
57
	public int getModelCount() {
58
		return fPreSelected.size() + fModels.size();
59
	}
60
61
	/**
62
	 * Returns the list of models stored in the model table
63
	 * @return the array of models
64
	 */
65
	public Object[] getModels() {
66
		return fModels.toArray();
67
	}
68
69
	/**
70
	 * Returns the list of preselected models stored in the model table
71
	 * @return the array of preselected models
72
	 */
73
	public Object[] getPreSelected() {
74
		return fPreSelected.toArray();
75
	}
76
77
	/**
78
	 * 
79
	 * @return whether or not the model table contains preselected models
80
	 */
81
	public boolean hasPreSelected() {
82
		return fPreSelected.size() > 0;
83
	}
84
85
	/**
86
	 * 
87
	 * @return whether or not the list of models is empty
88
	 */
89
	public boolean isEmpty() {
90
		return fModels.size() == 0;
91
	}
92
}
(-)src/org/eclipse/pde/internal/ui/nls/AvailableFilter.java (+52 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.pde.internal.ui.nls;
5
6
import java.util.Map;
7
import java.util.regex.Pattern;
8
import org.eclipse.jface.viewers.*;
9
import org.eclipse.pde.internal.core.util.PatternConstructor;
10
11
public class AvailableFilter extends ViewerFilter {
12
	public static final String WILDCARD = "*"; //$NON-NLS-1$
13
	private Pattern fPattern;
14
	private final Map selected;
15
	private final ILabelProvider labelProvider;
16
17
	public AvailableFilter(Map selected, ILabelProvider labelProvider) {
18
		setPattern(WILDCARD);
19
		this.selected = selected;
20
		this.labelProvider = labelProvider;
21
	}
22
23
	public boolean select(Viewer viewer, Object parentElement, Object element) {
24
		// filter out any items that are currently selected
25
		// on a full refresh, these will have been added back to the list
26
		if (selected.containsKey(element))
27
			return false;
28
29
		String displayName = labelProvider.getText(element);
30
		return matches(element.toString()) || matches(displayName);
31
	}
32
33
	private boolean matches(String s) {
34
		return fPattern.matcher(s.toLowerCase()).matches();
35
	}
36
37
	public boolean setPattern(String pattern) {
38
		String newPattern = pattern.toLowerCase();
39
40
		if (!newPattern.endsWith(WILDCARD))
41
			newPattern += WILDCARD;
42
		if (!newPattern.startsWith(WILDCARD))
43
			newPattern = WILDCARD + newPattern;
44
		if (fPattern != null) {
45
			String oldPattern = fPattern.pattern();
46
			if (newPattern.equals(oldPattern))
47
				return false;
48
		}
49
		fPattern = PatternConstructor.createPattern(newPattern, true);
50
		return true;
51
	}
52
}

Return to bug 201998