Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 90711 Details for
Bug 201998
Provide a wizard that generates NL fragments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
A patch partially implementing the proposed InternationalizationWizard
internationalizationWizard.diff (text/plain), 80.60 KB, created by
Aaron Maenpaa
on 2008-02-25 22:17:14 EST
(
hide
)
Description:
A patch partially implementing the proposed InternationalizationWizard
Filename:
MIME Type:
Creator:
Aaron Maenpaa
Created:
2008-02-25 22:17:14 EST
Size:
80.60 KB
patch
obsolete
>Index: src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java,v >retrieving revision 1.14 >diff -u -r1.14 GetNonExternalizedStringsOperation.java >--- src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java 16 Jan 2008 17:08:33 -0000 1.14 >+++ src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java 26 Feb 2008 03:10:55 -0000 >@@ -12,6 +12,7 @@ > > import java.lang.reflect.InvocationTargetException; > import java.util.ArrayList; >+import java.util.Iterator; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.runtime.*; >@@ -37,8 +38,12 @@ > private ModelChangeTable fModelChangeTable; > private boolean fCanceled; > >- public GetNonExternalizedStringsOperation(ISelection selection) { >+ //Azure: To indicate that only selected plug-ins under <code>fSelection</code> are to be externalized. >+ private boolean fExternalizeSelectedPluginsOnly; >+ >+ public GetNonExternalizedStringsOperation(ISelection selection, boolean externalizeSelectedPluginsOnly) { > fSelection = selection; >+ fExternalizeSelectedPluginsOnly = externalizeSelectedPluginsOnly; > } > > public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >@@ -56,12 +61,29 @@ > > fModelChangeTable = new ModelChangeTable(); > >- IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels(); >- monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length); >- for (int i = 0; i < pluginModels.length && !fCanceled; i++) { >- IProject project = pluginModels[i].getUnderlyingResource().getProject(); >- if (!WorkspaceModelManager.isBinaryProject(project)) >- getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1)); >+ /* >+ * Azure: This will add only the preselected plug-ins to the ModelChangeTable >+ * instead of adding the list of all plug-ins in the workspace. This is useful >+ * when the Internationalize action is run on a set of non-externalized plug-ins >+ * where there is no need to display all non-externalized plug-ins in the >+ * workspace, but only those selected. >+ */ >+ if (fExternalizeSelectedPluginsOnly) { >+ monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, fSelectedModels.size()); >+ Iterator iterator = fSelectedModels.iterator(); >+ while (iterator.hasNext() && !fCanceled) { >+ IProject project = (IProject) iterator.next(); >+ if (!WorkspaceModelManager.isBinaryProject(project)) >+ getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1)); >+ } >+ } else { >+ IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels(); >+ monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length); >+ for (int i = 0; i < pluginModels.length && !fCanceled; i++) { >+ IProject project = pluginModels[i].getUnderlyingResource().getProject(); >+ if (!WorkspaceModelManager.isBinaryProject(project)) >+ getUnExternalizedStrings(project, new SubProgressMonitor(monitor, 1)); >+ } > } > } > } >Index: src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java,v >retrieving revision 1.8 >diff -u -r1.8 GetNonExternalizedStringsAction.java >--- src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java 16 Jan 2008 17:08:33 -0000 1.8 >+++ src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java 26 Feb 2008 03:10:55 -0000 >@@ -23,12 +23,22 @@ > public class GetNonExternalizedStringsAction implements IWorkbenchWindowActionDelegate { > > private ISelection fSelection; >+ //Azure: To indicate that only selected plug-ins are to be externalized. False by default. >+ private boolean fExternalizeSelectedPluginsOnly = false; >+ >+ //Azure: To indicate that the post-externalization message dialog should not be displayed. >+ private boolean fSkipMessageDialog = false; > > public GetNonExternalizedStringsAction() { > } > > public void run(IAction action) { >- GetNonExternalizedStringsOperation runnable = new GetNonExternalizedStringsOperation(fSelection); >+ /* >+ * Azure: Pass <code>fExternalizeSelectedPluginsOnly</code> to the operation to indicate >+ * that only the plug-ins passed in the selection are to be externalized and such that >+ * only those are displayed on the change table in the ExternalizeStringsWizard. >+ */ >+ GetNonExternalizedStringsOperation runnable = new GetNonExternalizedStringsOperation(fSelection, fExternalizeSelectedPluginsOnly); > try { > PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); > } catch (InvocationTargetException e) { >@@ -47,8 +57,15 @@ > op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$ > } catch (final InterruptedException irex) { > } >- } else >- MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedMessage); >+ } else { >+ /* >+ * Azure: When the InternationalizeAction invokes the ExternalizeStringsAction, >+ * <code>fSkipMessageDialog</code> is set to true in order for no intermediate >+ * message to appear if all selected plug-ins were already externalized. >+ */ >+ if (!fSkipMessageDialog) >+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedMessage); >+ } > } > } > >@@ -61,4 +78,36 @@ > > public void init(IWorkbenchWindow window) { > } >+ >+ /** >+ * TODO: Azure Documentation >+ * @param externalizeSelectedPluginsOnly >+ */ >+ public void setExternalizeSelectedPluginsOnly(boolean externalizeSelectedPluginsOnly) { >+ fExternalizeSelectedPluginsOnly = externalizeSelectedPluginsOnly; >+ } >+ >+ /** >+ * TODO: Azure Documentation >+ * @return >+ */ >+ public boolean isExternalizeSelectedPluginsOnly() { >+ return fExternalizeSelectedPluginsOnly; >+ } >+ >+ /** >+ * TODO: Azure Documentation >+ * @param skipMessageDialog >+ */ >+ public void setSkipMessageDialog(boolean skipMessageDialog) { >+ this.fSkipMessageDialog = skipMessageDialog; >+ } >+ >+ /** >+ * TODO: Azure Documentation >+ * @return >+ */ >+ public boolean isSkipMessageDialog() { >+ return fSkipMessageDialog; >+ } > } >Index: src/org/eclipse/pde/internal/ui/PDEUIMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java,v >retrieving revision 1.360 >diff -u -r1.360 PDEUIMessages.java >--- src/org/eclipse/pde/internal/ui/PDEUIMessages.java 25 Feb 2008 20:43:47 -0000 1.360 >+++ src/org/eclipse/pde/internal/ui/PDEUIMessages.java 26 Feb 2008 03:10:52 -0000 >@@ -2454,6 +2454,26 @@ > > public static String ExternalizeStringsWizardPage_keySuggested; > >+ public static String InternationalizeAction_internationalizeTitle; >+ >+ public static String InternationalizeAction_internationalizeMessage; >+ >+ public static String InternationalizeWizard_title; >+ >+ public static String InternationalizeWizard_PluginPage_internationalizeList; >+ >+ public static String InternationalizeWizard_PluginPage_availableList; >+ >+ public static String InternationalizeWizard_PluginPage_filter; >+ >+ public static String InternationalizeWizard_PluginPage_pageTitle; >+ >+ public static String InternationalizeWizard_PluginPage_pageDescription; >+ >+ public static String InternationalizeWizard_LocalePage_pageTitle; >+ >+ public static String InternationalizeWizard_LocalePage_pageDescription; >+ > public static String NewProjectCreationPage_target; > > public static String NewProjectCreationPage_ftarget; >Index: src/org/eclipse/pde/internal/ui/pderesources.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties,v >retrieving revision 1.971 >diff -u -r1.971 pderesources.properties >--- src/org/eclipse/pde/internal/ui/pderesources.properties 25 Feb 2008 20:44:54 -0000 1.971 >+++ src/org/eclipse/pde/internal/ui/pderesources.properties 26 Feb 2008 03:10:54 -0000 >@@ -2026,6 +2026,17 @@ > 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. > IntroSection_undefinedProductId=Undefined Product ID > >+InternationalizeAction_internationalizeTitle=Internationalize Plug-ins >+InternationalizeAction_internationalizeMessage=All plug-ins have been internationalized >+InternationalizeWizard_title=Internationalize Plug-ins >+InternationalizeWizard_PluginPage_internationalizeList = P&lug-ins to Internationlize: >+InternationalizeWizard_PluginPage_availableList = P&lug-ins found: >+InternationalizeWizard_PluginPage_filter = Filter Available Plug-ins >+InternationalizeWizard_PluginPage_pageTitle=Internationalize Plug-ins >+InternationalizeWizard_PluginPage_pageDescription=Select the plug-ins to be internationalized. >+InternationalizeWizard_LocalePage_pageTitle=Internationalize Plug-ins >+InternationalizeWizard_LocalePage_pageDescription=Select the locales for which plug-ins should be internationalized. >+ > > MainTab_jreSection = Java Runtime Environment > EquinoxLaunchConfiguration_oldTarget=The org.eclipse.osgi plug-in is missing from this configuration. >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/plugin.properties,v >retrieving revision 1.210 >diff -u -r1.210 plugin.properties >--- plugin.properties 23 Jan 2008 19:37:52 -0000 1.210 >+++ plugin.properties 26 Feb 2008 03:10:49 -0000 >@@ -248,4 +248,6 @@ > > pluginsearch.action.name = Open Plug-in Artifact > pluginsearch.action.menu.name = Open &Plug-in Artifact... >-pluginsearch.action.desc = Open a plug-in artifact in the manifest editor >\ No newline at end of file >+pluginsearch.action.desc = Open a plug-in artifact in the manifest editor >+ >+Internationalize.label = Internationalize... >\ No newline at end of file >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/plugin.xml,v >retrieving revision 1.437 >diff -u -r1.437 plugin.xml >--- plugin.xml 23 Jan 2008 19:37:52 -0000 1.437 >+++ plugin.xml 26 Feb 2008 03:10:50 -0000 >@@ -587,6 +587,13 @@ > id="org.eclipse.pde.ui.ExternalizeStrings"> > </action> > <action >+ label="%Internationalize.label" >+ class="org.eclipse.pde.internal.ui.nls.InternationalizeAction" >+ menubarPath="org.eclipse.pde.ui.plugin.tools/group0" >+ enablesFor="+" >+ id="org.eclipse.pde.ui.Internationalize"> >+ </action> >+ <action > label="%OrganizeManifest.label" > helpContextId="org.eclipse.pde.doc.user.organize_manifest" > class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction" >@@ -625,7 +632,14 @@ > menubarPath="org.eclipse.pde.ui.manifest.tools/group0" > enablesFor="+" > id="org.eclipse.pde.ui.ExternalizeStrings"> >- </action> >+ </action> >+ <action >+ label="%Internationalize.label" >+ class="org.eclipse.pde.internal.ui.nls.InternationalizeAction" >+ menubarPath="org.eclipse.pde.ui.manifest.tools/group0" >+ enablesFor="+" >+ id="org.eclipse.pde.ui.Internationalize"> >+ </action> > <action > label="%OrganizeManifest.label" > helpContextId="org.eclipse.pde.doc.user.organize_manifest" >@@ -853,6 +867,13 @@ > id="org.eclipse.pde.ui.ExternalizeStrings"> > </action> > <action >+ label="%Internationalize.label" >+ class="org.eclipse.pde.internal.ui.nls.InternationalizeAction" >+ menubarPath="org.eclipse.pde.ui.project.tools/group1" >+ enablesFor="+" >+ id="org.eclipse.pde.ui.Internationalize"> >+ </action> >+ <action > label="%OrganizeManifest.label" > helpContextId="org.eclipse.pde.doc.user.organize_manifest" > class="org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsAction" >Index: src/org/eclipse/pde/internal/ui/nls/NLSFragmentsGenerator.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/NLSFragmentsGenerator.java >diff -N src/org/eclipse/pde/internal/ui/nls/NLSFragmentsGenerator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/NLSFragmentsGenerator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,200 @@ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.List; >+import java.util.Locale; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.jface.wizard.IWizardContainer; >+import org.eclipse.pde.core.plugin.IPluginModelBase; >+import org.eclipse.pde.internal.core.TargetPlatformHelper; >+import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase; >+import org.eclipse.pde.internal.ui.PDEPlugin; >+import org.eclipse.pde.internal.ui.wizards.IProjectProvider; >+import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; >+import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard.ImportQuery; >+import org.eclipse.pde.internal.ui.wizards.plugin.FragmentFieldData; >+import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationOperation; >+import org.eclipse.swt.widgets.Shell; >+ >+public class NLSFragmentsGenerator { >+ >+ private List pluginsToBeInternationalized; >+ //private List requiredLocales; >+ >+ private static final String PERIOD = "."; //$NON-NLS-1$ >+ private static final String MIN_MINOR = "0"; //$NON-NLS-1$ >+ private static final String MAX_MINOR = "9"; //$NON-NLS-1$ >+ private static final String NL_FRAGMENT_EXTENSION = ".nl1"; //$NON-NLS-1$ >+ private static final String LEFT_SQUARE_BRACKET = "["; //$NON-NLS-1$ >+ private static final String RIGHT_PARENTHESIS = ")"; //$NON-NLS-1$ >+ private static final String DEFAULT_VERSION = "1.0.0"; //$NON-NLS-1$ >+ private static final String VERSION_FORMAT_WITH_QUALIFIER = "\\d+\\.\\d+\\.\\d+\\..+"; //$NON-NLS-1$ >+ private static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$ >+ private static final String PROPERTIES_FILE_PREFIX = "plugin_"; //$NON-NLS-1$ >+ >+ private FragmentFieldData fFragmentData; >+ private IProjectProvider fProjectProvider; >+ private IPluginModelBase currentPlugin; >+ private IWizardContainer container; >+ private IProject currentPluginProject; >+ >+ public NLSFragmentsGenerator(List plugins, List locales, IWizardContainer container) { >+ this.pluginsToBeInternationalized = plugins; >+ //this.requiredLocales = locales; >+ this.container = container; >+ >+ internationalizePlugins(); >+ } >+ >+ private void internationalizePlugins() { >+ for (Object pluginObject : pluginsToBeInternationalized) { >+ IPluginModelBase plugin = (IPluginModelBase) pluginObject; >+ createNLFragment(plugin); >+ >+ if (currentPlugin instanceof ExternalPluginModelBase) { >+ doImportOperation(container.getShell(), PluginImportOperation.IMPORT_WITH_SOURCE, currentPlugin, true); >+ } >+ >+ IProject currentFragmentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION); >+ createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.FRENCH); >+ createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.ENGLISH); >+ createLocaleSpecificPropertiesFile(currentFragmentProject, Locale.CHINA); >+ >+ if (currentPlugin instanceof ExternalPluginModelBase) { >+ try { >+ currentPluginProject.delete(true, true, new NullProgressMonitor()); >+ } catch (CoreException c) { >+ System.out.println(c); >+ } >+ } >+ } >+ } >+ >+ private void createNLFragment(IPluginModelBase plugin) { >+ fFragmentData = new FragmentFieldData(); >+ >+ currentPlugin = plugin; >+ currentPluginProject = ResourcesPlugin.getWorkspace().getRoot().getProject(currentPlugin.getPluginBase().getId()); >+ >+ populateFieldData(); >+ >+ fProjectProvider = new IProjectProvider() { >+ public String getProjectName() { >+ return currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION; >+ } >+ >+ public IProject getProject() { >+ return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()); >+ } >+ >+ public IPath getLocationPath() { >+ return new Path(Platform.getLocation().toOSString()); >+ } >+ }; >+ >+ try { >+ container.run(false, true, new NewProjectCreationOperation(fFragmentData, fProjectProvider, null)); >+ } catch (InvocationTargetException e) { >+ PDEPlugin.logException(e); >+ } catch (InterruptedException e) { >+ } >+ } >+ >+ private void populateFieldData() { >+ >+ fFragmentData.setId(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION); >+ fFragmentData.setVersion(DEFAULT_VERSION); >+ fFragmentData.setMatch(0); >+ >+ fFragmentData.setPluginId(currentPlugin.getPluginBase().getId()); >+ fFragmentData.setPluginVersion(incrementRelease(currentPlugin.getPluginBase().getVersion())); >+ fFragmentData.setName(currentPlugin.getPluginBase().getId() + NL_FRAGMENT_EXTENSION + " Fragment"); //$NON-NLS-1$ >+ fFragmentData.setProvider(""); //$NON-NLS-1$ >+ fFragmentData.setSimple(true); >+ >+ if (!(currentPlugin instanceof ExternalPluginModelBase)) { >+ fFragmentData.setSourceFolderName("src"); //$NON-NLS-1$ >+ fFragmentData.setOutputFolderName("bin"); //$NON-NLS-1$ >+ } >+ >+ fFragmentData.setLegacy(false); >+ fFragmentData.setTargetVersion(Double.toString(ensureTargetVersionCompatibility(TargetPlatformHelper.getTargetVersion()))); >+ fFragmentData.setHasBundleStructure(true); >+ fFragmentData.setOSGiFramework(null); >+ fFragmentData.setWorkingSets(null); >+ } >+ >+ private String incrementRelease(String oldVersion) { >+ >+ if (oldVersion.matches(VERSION_FORMAT_WITH_QUALIFIER)) { >+ oldVersion = oldVersion.substring(0, oldVersion.lastIndexOf(PERIOD)); >+ } >+ >+ String newVersion = LEFT_SQUARE_BRACKET + oldVersion + ','; >+ String oldMinor = oldVersion.substring(oldVersion.indexOf(PERIOD) + 1, oldVersion.lastIndexOf(PERIOD)); >+ String oldMicro = oldVersion.substring(oldVersion.lastIndexOf(PERIOD) + 1); >+ >+ if (oldMinor.compareTo(MAX_MINOR) == 0) { >+ String major = Integer.toString(Integer.valueOf(oldVersion.substring(0, oldVersion.indexOf(PERIOD))) + 1); >+ newVersion += major + PERIOD + MIN_MINOR + PERIOD + oldMicro + RIGHT_PARENTHESIS; >+ } else { >+ String major = oldVersion.substring(0, oldVersion.indexOf(PERIOD)); >+ String newMinor = Integer.toString(Integer.valueOf(oldMinor) + 1); >+ newVersion += major + PERIOD + newMinor + PERIOD + oldMicro + RIGHT_PARENTHESIS; >+ } >+ >+ return newVersion; >+ } >+ >+ private void createLocaleSpecificPropertiesFile(IProject fragmentProject, Locale locale) { >+ >+ IFile pluginProperties; >+ >+ if (currentPlugin instanceof ExternalPluginModelBase) { >+ pluginProperties = currentPluginProject.getFile("plugin.properties"); //$NON-NLS-1$ >+ } else { >+ pluginProperties = currentPlugin.getUnderlyingResource().getProject().getFile("plugin.properties"); //$NON-NLS-1$ >+ } >+ >+ IFile localeProperties = fragmentProject.getFile(PROPERTIES_FILE_PREFIX + locale.getLanguage() + PROPERTIES_FILE_EXTENSION); >+ >+ if (!localeProperties.exists()) { >+ try { >+ pluginProperties.copy(localeProperties.getFullPath(), false, null); >+ >+ } catch (Exception e) { >+ System.out.println(e); >+ } >+ } >+ } >+ >+ private double ensureTargetVersionCompatibility(double targetVersion) { >+ if (targetVersion < 3.0) { >+ return 3.4; >+ } >+ return targetVersion; >+ } >+ >+ public static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase model, final boolean forceAutobuild) { >+ doImportOperation(shell, importType, new IPluginModelBase[] {model}, forceAutobuild); >+ } >+ >+ public static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase[] models, final boolean forceAutobuild) { >+ doImportOperation(shell, importType, models, forceAutobuild, false); >+ } >+ >+ private static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase[] models, final boolean forceAutobuild, final boolean launchedConfiguration) { >+ PluginImportOperation.IImportQuery query = new ImportQuery(shell); >+ PluginImportOperation.IImportQuery executionQuery = new ImportQuery(shell); >+ final PluginImportOperation op = new PluginImportOperation(models, importType, query, executionQuery, forceAutobuild); >+ op.setLaunchedConfiguration(launchedConfiguration); >+ >+ try { >+ PDEPlugin.getWorkspace().run(op, new NullProgressMonitor()); >+ } catch (CoreException e) { >+ PDEPlugin.logException(e); >+ } >+ >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardOpenOperation.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardOpenOperation.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardOpenOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardOpenOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+package org.eclipse.pde.internal.ui.nls; >+ >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.jobs.IJobManager; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.IWizardContainer; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.swt.custom.BusyIndicator; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * A helper class to open an InternationalizeWizard dialog. >+ * >+ * @author Team Azure >+ */ >+public class InternationalizeWizardOpenOperation { >+ >+ private InternationalizeWizard fWizard; >+ >+ public InternationalizeWizardOpenOperation(InternationalizeWizard wizard) { >+ Assert.isNotNull(wizard); >+ fWizard = wizard; >+ } >+ >+ public int run(final Shell parent, final String dialogTitle) throws InterruptedException { >+ Assert.isNotNull(dialogTitle); >+ final IJobManager manager = Job.getJobManager(); >+ final int[] result = new int[1]; >+ final InterruptedException[] canceled = new InterruptedException[1]; >+ >+ Runnable r = new Runnable() { >+ public void run() { >+ try { >+ manager.beginRule(ResourcesPlugin.getWorkspace().getRoot(), null); >+ >+ Dialog dialog = new WizardDialog(parent, fWizard); >+ dialog.create(); >+ >+ IWizardContainer wizardContainer = (IWizardContainer) dialog; >+ if (wizardContainer.getCurrentPage() == null) { >+ //Close the dialog if there are no pages >+ result[0] = Window.CANCEL; >+ } else { >+ //Open the wizard dialog >+ result[0] = dialog.open(); >+ } >+ >+ } catch (OperationCanceledException e) { >+ canceled[0] = new InterruptedException(e.getMessage()); >+ } finally { >+ manager.endRule(ResourcesPlugin.getWorkspace().getRoot()); >+ } >+ } >+ }; >+ BusyIndicator.showWhile(parent.getDisplay(), r); >+ if (canceled[0] != null) >+ throw canceled[0]; >+ return result[0]; >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeAction.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeAction.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.lang.reflect.InvocationTargetException; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.pde.internal.ui.PDEPlugin; >+import org.eclipse.pde.internal.ui.PDEUIMessages; >+import org.eclipse.ui.*; >+ >+/** >+ * This action class is responsible for creating and initializing the >+ * InternationalizeWizard. >+ * >+ * @author Team Azure >+ * >+ */ >+public class InternationalizeAction implements IWorkbenchWindowActionDelegate { >+ >+ private IStructuredSelection fSelection; >+ >+ public InternationalizeAction() { >+ } >+ >+ public void run(IAction action) { >+ //Create an InternationalizeOperation on the workbench selection. >+ InternationalizeOperation runnable = new InternationalizeOperation(fSelection); >+ try { >+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); >+ } catch (InvocationTargetException e) { >+ } catch (InterruptedException e) { >+ } finally { >+ if (runnable.wasCanceled()) { >+ return; >+ } >+ >+ /* Get the plugin model table containing the list of workspace and >+ * external plug-ins >+ */ >+ InternationalizeModelTable pluginTable = runnable.getPluginTable(); >+ >+ if (!pluginTable.isEmpty()) { >+ >+ InternationalizeWizard wizard = new InternationalizeWizard(action, pluginTable); >+ wizard.init(PlatformUI.getWorkbench(), fSelection); >+ >+ //Create an operation to start and run the wizard >+ InternationalizeWizardOpenOperation op = new InternationalizeWizardOpenOperation(wizard); >+ try { >+ op.run(PDEPlugin.getActiveWorkbenchShell(), ""); //$NON-NLS-1$ >+ } catch (final InterruptedException irex) { >+ } >+ } else { >+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PDEUIMessages.InternationalizeAction_internationalizeTitle, PDEUIMessages.InternationalizeAction_internationalizeMessage); >+ } >+ } >+ } >+ >+ public void selectionChanged(IAction action, ISelection selection) { >+ fSelection = (IStructuredSelection) selection; >+ } >+ >+ public void dispose() { >+ } >+ >+ public void init(IWorkbenchWindow window) { >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardLocalePage.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardLocalePage.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardLocalePage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardLocalePage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,572 @@ >+/** >+ * >+ */ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.util.*; >+import java.util.List; >+import java.util.regex.Pattern; >+import org.eclipse.core.runtime.*; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.*; >+import org.eclipse.jface.wizard.IWizardContainer; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.pde.core.IModelProviderEvent; >+import org.eclipse.pde.core.IModelProviderListener; >+import org.eclipse.pde.internal.core.PDECore; >+import org.eclipse.pde.internal.core.util.PatternConstructor; >+import org.eclipse.pde.internal.ui.*; >+import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; >+import org.eclipse.pde.internal.ui.util.SWTUtil; >+import org.eclipse.pde.internal.ui.wizards.ListUtil; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.ScrolledComposite; >+import org.eclipse.swt.events.*; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.*; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.progress.WorkbenchJob; >+ >+/** >+ * @author Robbie >+ * >+ */ >+public class InternationalizeWizardLocalePage extends WizardPage implements IModelProviderListener { >+ >+ public static final String PAGE_NAME = "InternationalizeWizardLocalePage"; //$NON-NLS-1$ >+ >+ protected Locale[] fModels = new Locale[0]; >+ private String fLocation; >+ >+ protected TableViewer fSelectedListViewer; >+ private boolean fRefreshNeeded = true; >+ >+ private Label fCountLabel; >+ private TableViewer fAvailableListViewer; >+ >+ // this job is used to delay the full filter refresh for 200 milliseconds in case the user is still typing >+ private WorkbenchJob fFilterJob; >+ private Text fFilterText; >+ private AvailableFilter fFilter; >+ >+ // fSelected is used to track the selection in a HashMap so we can efficiently >+ // filter selected items out of the available item list >+ private HashMap fSelected; >+ // used to block the selection listeners from updating button enablement when programatically removing items >+ private boolean fBlockSelectionListeners; >+ private Button fAddButton; >+ private Button fAddAllButton; >+ private Button fRemoveButton; >+ private Button fRemoveAllButton; >+ >+ private InternationalizeModelTable fInternationalizeModelTable; >+ >+ private class AvailableFilter extends ViewerFilter { >+ private Pattern fPattern; >+ >+ public AvailableFilter() { >+ setPattern("*"); //$NON-NLS-1$ >+ } >+ >+ public boolean select(Viewer viewer, Object parentElement, Object element) { >+ // filter out any items that are currently selected >+ // on a full refresh, these will have been added back to the list >+ if (fSelected.containsKey(element)) >+ return false; >+ if (!(element instanceof Locale)) >+ return false; >+ String localeName = ((Locale) element).toString(); >+ if (fPattern.matcher(localeName).matches()) >+ return true; >+ return false; >+ } >+ >+ public boolean setPattern(String newPattern) { >+ if (!newPattern.endsWith("*")) //$NON-NLS-1$ >+ newPattern += "*"; //$NON-NLS-1$ >+ if (!newPattern.startsWith("*")) //$NON-NLS-1$ >+ newPattern = "*" + newPattern; //$NON-NLS-1$ >+ if (fPattern != null) { >+ String oldPattern = fPattern.pattern(); >+ if (newPattern.equals(oldPattern)) >+ return false; >+ } >+ fPattern = PatternConstructor.createPattern(newPattern, true); >+ return true; >+ } >+ } >+ >+ /*private String[] getLocales() { >+ Locale[] locales = Locale.getAvailableLocales(); >+ String[] result = new String[locales.length]; >+ for (int i = 0; i < locales.length; i++) { >+ Locale locale = locales[i]; >+ StringBuffer buffer = new StringBuffer(); >+ buffer.append(locale.toString()); >+ buffer.append(" - "); //$NON-NLS-1$ >+ buffer.append(locale.getDisplayName()); >+ result[i] = buffer.toString(); >+ } >+ return result; >+ }*/ >+ >+ private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider { >+ public Object[] getElements(Object parent) { >+ return fInternationalizeModelTable.getModels(); >+ } >+ } >+ >+ private class SelectedContentProvider extends DefaultContentProvider implements IStructuredContentProvider { >+ public Object[] getElements(Object parent) { >+ return null; >+ } >+ } >+ >+ public InternationalizeWizardLocalePage(InternationalizeModelTable modelTable, String pageName) { >+ super(pageName); >+ PDEPlugin.getDefault().getLabelProvider().connect(this); >+ PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this); >+ >+ fInternationalizeModelTable = modelTable; >+ fSelected = new HashMap(); >+ >+ IWizardContainer container = getContainer(); >+ if (container != null) >+ container.updateButtons(); >+ } >+ >+ private void addFilter() { >+ fFilter = new AvailableFilter(); >+ fAvailableListViewer.addFilter(fFilter); >+ fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$ >+ public IStatus runInUIThread(IProgressMonitor monitor) { >+ handleFilter(); >+ return Status.OK_STATUS; >+ } >+ }; >+ fFilterJob.setSystem(true); >+ } >+ >+ private void handleFilter() { >+ boolean changed = false; >+ String newFilter; >+ if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0) >+ newFilter = "*"; //$NON-NLS-1$ >+ changed = fFilter.setPattern(newFilter); >+ if (changed) { >+ fAvailableListViewer.getTable().setRedraw(false); >+ fAvailableListViewer.refresh(); >+ fAvailableListViewer.getTable().setRedraw(true); >+ updateButtonEnablement(false, false); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) >+ */ >+ public void createControl(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 3; >+ layout.makeColumnsEqualWidth = false; >+ layout.horizontalSpacing = 5; >+ layout.verticalSpacing = 10; >+ container.setLayout(layout); >+ >+ createScrollArea(container); >+ createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH)); >+ createButtonArea(container); >+ createLocaleList(container).setLayoutData(new GridData(GridData.FILL_BOTH)); >+ updateCount(); >+ >+ // create container for buttons >+ Composite buttonContainer = new Composite(container, SWT.NONE); >+ buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create()); >+ >+ addViewerListeners(); >+ addFilter(); >+ >+ initialize(); >+ setControl(container); >+ Dialog.applyDialogFont(container); >+ PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE); >+ } >+ >+ protected Composite createLocaleList(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ container.setLayout(layout); >+ container.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ Label label = new Label(container, SWT.NONE); >+ label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_internationalizeList); >+ >+ Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); >+ GridData gd = new GridData(GridData.FILL_BOTH); >+ gd.widthHint = 225; >+ table.setLayoutData(gd); >+ >+ fSelectedListViewer = new TableViewer(table); >+ fSelectedListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); >+ fSelectedListViewer.setContentProvider(new SelectedContentProvider()); >+ //fSelectedListViewer.setInput(); TODO Pass proper input to TableViewer >+ fSelectedListViewer.setComparator(ListUtil.NAME_COMPARATOR); >+ return container; >+ } >+ >+ protected boolean isRefreshNeeded() { >+ if (fRefreshNeeded) { >+ fRefreshNeeded = false; >+ return true; >+ } >+ if (fLocation == null) { >+ return true; >+ } >+ return false; >+ } >+ >+ protected void addLocale(Locale model, ArrayList selected) { >+ if (!selected.contains(model)) { >+ selected.add(model); >+ } >+ } >+ >+ public List getLocalesForInternationalization() { >+ TableItem[] items = fSelectedListViewer.getTable().getItems(); >+ List result = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ result.add(items[i].getData()); >+ } >+ return result; >+ } >+ >+ public void storeSettings() { >+ IDialogSettings settings = getDialogSettings(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent) >+ */ >+ public void modelsChanged(IModelProviderEvent event) { >+ fRefreshNeeded = true; >+ } >+ >+ private void initialize() { >+ updateButtonEnablement(true, true); >+ setPageComplete(false); >+ } >+ >+ private void addViewerListeners() { >+ fAvailableListViewer.addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ handleAdd(); >+ } >+ }); >+ >+ fSelectedListViewer.addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ handleRemove(); >+ } >+ }); >+ >+ fAvailableListViewer.addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!fBlockSelectionListeners) >+ updateSelectionBasedEnablement(event.getSelection(), true); >+ } >+ }); >+ >+ fSelectedListViewer.addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!fBlockSelectionListeners) >+ updateSelectionBasedEnablement(event.getSelection(), false); >+ } >+ }); >+ >+ fFilterText.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ fFilterJob.cancel(); >+ fFilterJob.schedule(200); >+ } >+ }); >+ >+ } >+ >+ private Composite createAvailableList(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ container.setLayout(layout); >+ container.setLayoutData(new GridData()); >+ >+ Label label = new Label(container, SWT.NONE); >+ label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_availableList); >+ >+ Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); >+ GridData gd = new GridData(GridData.FILL_BOTH); >+ gd.heightHint = 200; >+ gd.widthHint = 225; >+ table.setLayoutData(gd); >+ >+ fAvailableListViewer = new TableViewer(table); >+ fAvailableListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); >+ fAvailableListViewer.setContentProvider(new ContentProvider()); >+ //fAvailableListViewer.setInput(); TODO Pass proper input to TableViewer >+ fAvailableListViewer.setComparator(ListUtil.NAME_COMPARATOR); >+ >+ return container; >+ } >+ >+ private Composite createButtonArea(Composite parent) { >+ ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = layout.marginHeight = 0; >+ comp.setLayoutData(new GridData(GridData.FILL_VERTICAL)); >+ Composite container = new Composite(comp, SWT.NONE); >+ layout = new GridLayout(); >+ layout.marginWidth = 0; >+ container.setLayout(layout); >+ GridData gd = new GridData(GridData.FILL_VERTICAL); >+ gd.verticalIndent = 15; >+ container.setLayoutData(gd); >+ >+ fAddButton = new Button(container, SWT.PUSH); >+ fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add); >+ fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fAddButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleAdd(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fAddButton); >+ >+ fAddAllButton = new Button(container, SWT.PUSH); >+ fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll); >+ fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fAddAllButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleAddAll(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fAddAllButton); >+ >+ fRemoveButton = new Button(container, SWT.PUSH); >+ fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove); >+ fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fRemoveButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleRemove(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fRemoveButton); >+ >+ fRemoveAllButton = new Button(container, SWT.PUSH); >+ fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll); >+ fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fRemoveAllButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleRemoveAll(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fRemoveAllButton); >+ >+ fCountLabel = new Label(container, SWT.NONE); >+ fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); >+ comp.setContent(container); >+ comp.setMinHeight(250); >+ comp.setExpandHorizontal(true); >+ comp.setExpandVertical(true); >+ return container; >+ } >+ >+ private Composite createScrollArea(Composite parent) { >+ Group container = new Group(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(2, false); >+ layout.marginWidth = layout.marginHeight = 6; >+ container.setLayout(layout); >+ >+ GridData gd = new GridData(GridData.FILL_HORIZONTAL); >+ gd.horizontalSpan = 3; >+ container.setLayoutData(gd); >+ container.setText(PDEUIMessages.InternationalizeWizard_PluginPage_filter); >+ >+ Label filterLabel = new Label(container, SWT.NONE); >+ filterLabel.setText(PDEUIMessages.ImportWizard_DetailedPage_search); >+ >+ fFilterText = new Text(container, SWT.BORDER); >+ fFilterText.setText(""); //$NON-NLS-1$ >+ gd = new GridData(GridData.FILL_HORIZONTAL); >+ fFilterText.setLayoutData(gd); >+ >+ return container; >+ } >+ >+ public void setVisible(boolean visible) { >+ super.setVisible(visible); >+ } >+ >+ protected void refreshPage() { >+ fSelectedListViewer.getTable().removeAll(); >+ fSelected = new HashMap(); >+ fAvailableListViewer.refresh(); >+ pageChanged(); >+ } >+ >+ protected void pageChanged() { >+ pageChanged(false, false); >+ } >+ >+ protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) { >+ updateCount(); >+ updateButtonEnablement(doAddEnablement, doRemoveEnablement); >+ setPageComplete(fSelectedListViewer.getTable().getItemCount() > 0); >+ } >+ >+ private void updateCount() { >+ 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()}))); >+ fCountLabel.getParent().layout(); >+ } >+ >+ private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) { >+ int availableCount = fAvailableListViewer.getTable().getItemCount(); >+ int importCount = fSelectedListViewer.getTable().getItemCount(); >+ >+ if (doAddEnablement) >+ updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true); >+ if (doRemoveEnablement) >+ updateSelectionBasedEnablement(fSelectedListViewer.getSelection(), false); >+ >+ fAddAllButton.setEnabled(availableCount > 0); >+ fRemoveAllButton.setEnabled(importCount > 0); >+ } >+ >+ private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) { >+ if (available) >+ fAddButton.setEnabled(!theSelection.isEmpty()); >+ else >+ fRemoveButton.setEnabled(!theSelection.isEmpty()); >+ } >+ >+ private void handleAdd() { >+ IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection(); >+ if (ssel.size() > 0) { >+ Table table = fAvailableListViewer.getTable(); >+ int index = table.getSelectionIndices()[0]; >+ Object[] selection = ssel.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < selection.length; i++) { >+ doAdd(selection[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); >+ pageChanged(true, false); >+ } >+ } >+ >+ private void handleAddAll() { >+ TableItem[] items = fAvailableListViewer.getTable().getItems(); >+ >+ ArrayList data = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ data.add(items[i].getData()); >+ } >+ if (data.size() > 0) { >+ Object[] datas = data.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < datas.length; i++) { >+ doAdd(datas[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ pageChanged(true, false); >+ } >+ } >+ >+ private void handleRemove() { >+ IStructuredSelection ssel = (IStructuredSelection) fSelectedListViewer.getSelection(); >+ if (ssel.size() > 0) { >+ Table table = fSelectedListViewer.getTable(); >+ int index = table.getSelectionIndices()[0]; >+ Object[] selection = ssel.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < selection.length; i++) { >+ doRemove(selection[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); >+ pageChanged(false, true); >+ } >+ } >+ >+ private void doAdd(Object o) { >+ fInternationalizeModelTable.removeModel(o); >+ fSelectedListViewer.add(o); >+ fAvailableListViewer.remove(o); >+ fSelected.put(o, null); >+ } >+ >+ private void doRemove(Object o) { >+ fInternationalizeModelTable.addModel(o); >+ fSelected.remove(o); >+ fSelectedListViewer.remove(o); >+ fAvailableListViewer.add(o); >+ } >+ >+ // used to prevent flicker during operations that move items between lists >+ private void setRedraw(boolean redraw) { >+ fAvailableListViewer.getTable().setRedraw(redraw); >+ fSelectedListViewer.getTable().setRedraw(redraw); >+ } >+ >+ private void handleRemoveAll() { >+ TableItem[] items = fSelectedListViewer.getTable().getItems(); >+ >+ ArrayList data = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ data.add(items[i].getData()); >+ } >+ if (data.size() > 0) { >+ Object[] datas = data.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < datas.length; i++) { >+ doRemove(datas[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ pageChanged(false, true); >+ } >+ } >+ >+ public void dispose() { >+ PDEPlugin.getDefault().getLabelProvider().disconnect(this); >+ PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this); >+ } >+ >+ private void setBlockSelectionListeners(boolean blockSelectionListeners) { >+ fBlockSelectionListeners = blockSelectionListeners; >+ } >+ >+ public boolean isCurrentPage() { >+ return super.isCurrentPage(); >+ } >+ >+ public boolean canFlipToNextPage() { >+ if (fSelectedListViewer.getTable().getItems().length > 0) { >+ return true; >+ } >+ return false; >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,193 @@ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.util.*; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.jface.wizard.Wizard; >+import org.eclipse.pde.core.plugin.IPluginModelBase; >+import org.eclipse.pde.internal.core.plugin.ExternalPluginModel; >+import org.eclipse.pde.internal.ui.*; >+import org.eclipse.ui.IImportWizard; >+import org.eclipse.ui.IWorkbench; >+ >+/** >+ * An InternationalizeWizard is responsible for internationalizing a list of >+ * specified plug-ins (workspace and external) to a set of specified locales. >+ * This involves creating an NLS fragment project for every plug-in, which would >+ * contain properties files for each specified locale. The first page of the wizard >+ * allows the user to select the desired plug-ins and the second page the desired >+ * locales. Also, the wizard ensures the plug-ins are externalized before proceeding >+ * with internationlization. >+ * >+ * @author Team Azure >+ * >+ */ >+public class InternationalizeWizard extends Wizard implements IImportWizard { >+ >+ private static final String STORE_SECTION = "InternationalizeWizard"; //$NON-NLS-1$ >+ >+ private IAction action; >+ private IStructuredSelection selection; >+ >+ //An intermediate selection passed to the ExternalizeStringsWizard >+ private IStructuredSelection externalizeSelection; >+ >+ private InternationalizeWizardPluginPage page1; >+ private InternationalizeWizardLocalePage page2; >+ >+ //Contains the list of plug-ins to be internationalized >+ private InternationalizeModelTable fInternationalizePluginModelTable; >+ >+ //Contains the list of locales >+ private InternationalizeModelTable fInternationalizeLocaleModelTable; >+ >+ public InternationalizeWizard(IAction action, InternationalizeModelTable pluginTable) { >+ fInternationalizePluginModelTable = pluginTable; >+ populateLocaleModelTable(); >+ IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings(); >+ setDialogSettings(getSettingsSection(masterSettings)); >+ setDefaultPageImageDescriptor(PDEPluginImages.DESC_EXTSTR_WIZ); >+ setWindowTitle(PDEUIMessages.InternationalizeWizard_title); >+ this.action = action; >+ } >+ >+ /** >+ * Populates the local InternationalizeModelTable with the list of all >+ * available locales >+ */ >+ private void populateLocaleModelTable() { >+ fInternationalizeLocaleModelTable = new InternationalizeModelTable(); >+ for (Locale locale : Locale.getAvailableLocales()) { >+ fInternationalizeLocaleModelTable.addModel(locale); >+ } >+ } >+ >+ /** >+ * Initialises selections >+ */ >+ public void init(IWorkbench workbench, IStructuredSelection selection) { >+ this.selection = selection; >+ externalizeSelection = this.selection; >+ } >+ >+ /** >+ * Adds the plug-in and locale pages to the wizard >+ */ >+ public void addPages() { >+ setNeedsProgressMonitor(true); >+ page1 = new InternationalizeWizardPluginPage(fInternationalizePluginModelTable, "Plug-ins"); //$NON-NLS-1$ >+ addPage(page1); >+ >+ page2 = new InternationalizeWizardLocalePage(fInternationalizeLocaleModelTable, "Locales"); //$NON-NLS-1$ >+ addPage(page2); >+ } >+ >+ /** >+ * >+ * @param master >+ * @return the created setting for the InternationalizeWizard >+ */ >+ private IDialogSettings getSettingsSection(IDialogSettings master) { >+ IDialogSettings setting = master.getSection(STORE_SECTION); >+ if (setting == null) { >+ setting = master.addNewSection(STORE_SECTION); >+ } >+ return setting; >+ } >+ >+ /** >+ * >+ * @return the list of plug-ins selected for internationalization >+ */ >+ private List getPluginModelsForInternationalization() { >+ return page1.getModelsToInternationalize(); >+ } >+ >+ /** >+ * >+ * @return the list of locales specified for internationalization >+ */ >+ private List getLocalesForInternationalization() { >+ return page2.getLocalesForInternationalization(); >+ } >+ >+ public boolean performFinish() { >+ page1.storeSettings(); >+ >+ /*ArrayList pluginModels = (ArrayList) getPluginModelsForInternationalization(); >+ final IPluginModelBase[] plugins = (IPluginModelBase[]) pluginModels.toArray(new IPluginModelBase[pluginModels.size()]); >+ >+ ArrayList localeModels = (ArrayList) getLocalesForInternationalization(); >+ final Locale[] locales = (Locale[]) localeModels.toArray(new IPluginModelBase[pluginModels.size()]); >+ */ >+ >+ //Generate an NL fragment project for each of the selected plug-ins with the specified locales >+ new NLSFragmentsGenerator(getPluginModelsForInternationalization(), getLocalesForInternationalization(), this.getContainer()); >+ return true; >+ } >+ >+ /** >+ * >+ * @param currentPage >+ * @return the next wizard page >+ */ >+ public IWizardPage getNextPage(IWizardPage currentPage) { >+ if (currentPage.equals(page1)) { >+ //page.setVisible(false); >+ ensurePluginsAreExternalized(); >+ //page.setVisible(true); >+ >+ return page2; >+ } >+ return currentPage; >+ } >+ >+ /** >+ * >+ * @param currentPage >+ * @return the previous wizard page >+ */ >+ public IWizardPage getPreviousPage(IWizardPage currentPage) { >+ return currentPage.equals(page1) ? null : page1; >+ } >+ >+ public boolean canFinish() { >+ return !page1.isCurrentPage() && page1.getNextPage().isPageComplete(); >+ } >+ >+ /** >+ * Checks whether or not the selected plug-ins are already externalized. This >+ * method invokes the ExternalizeStringsWizard on the selected plug-ins. >+ */ >+ public void ensurePluginsAreExternalized() { >+ GetNonExternalizedStringsAction externalize = new GetNonExternalizedStringsAction(); >+ >+ List<IProject> projects = new ArrayList<IProject>(); >+ List<IPluginModelBase> pluginModels = getPluginModelsForInternationalization(); >+ selection = new StructuredSelection(pluginModels); //Save the plug-ins selected for internationalization in a StructuredSelection >+ for (IPluginModelBase pluginModel : pluginModels) { >+ //Externalize only workspace plug-ins since external plug-ins are already externalized >+ if (!(pluginModel instanceof ExternalPluginModel)) { >+ IProject project = pluginModel.getUnderlyingResource().getProject(); >+ projects.add(project); >+ } >+ } >+ >+ //Set the selection for the non-externalized plug-ins that >+ //should be passed to the ExternalizeStringsWizard >+ externalizeSelection = new StructuredSelection(projects); >+ >+ externalize.selectionChanged(action, externalizeSelection); >+ externalize.setExternalizeSelectedPluginsOnly(true); >+ externalize.setSkipMessageDialog(true); >+ externalize.run(action); >+ } >+ >+ public boolean performCancel() { >+ return super.performCancel(); >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeOperation.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeOperation.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,93 @@ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.pde.core.plugin.IPluginModelBase; >+import org.eclipse.pde.core.plugin.PluginRegistry; >+import org.eclipse.pde.internal.core.WorkspaceModelManager; >+import org.eclipse.pde.internal.ui.PDEUIMessages; >+ >+/** >+ * InternationalizeOperation is responsible for populating a plug-in model table >+ * containing the list of plug-ins (workspace and external) prior to running the >+ * wizard. An instance of this class must be created before creating an >+ * InternationlizeWizard instance. >+ * >+ * @author Team Azure >+ * >+ */ >+public class InternationalizeOperation implements IRunnableWithProgress { >+ >+ private ISelection fSelection; >+ private ArrayList fSelectedModels; >+ private InternationalizeModelTable fModelPluginTable; >+ private boolean fCanceled; >+ >+ /** >+ * >+ * @param selection represents the preselected plug-in projects in the workbench >+ */ >+ public InternationalizeOperation(ISelection selection) { >+ fSelection = selection; >+ } >+ >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >+ >+ if (fSelection instanceof IStructuredSelection) { >+ >+ Object[] elems = ((IStructuredSelection) fSelection).toArray(); >+ >+ fSelectedModels = new ArrayList(elems.length); >+ for (int i = 0; i < elems.length; i++) { >+ //If a file was selected, get its parent project >+ if (elems[i] instanceof IFile) >+ elems[i] = ((IFile) elems[i]).getProject(); >+ >+ //Add the project to the preselected model list >+ if (elems[i] instanceof IProject && WorkspaceModelManager.isPluginProject((IProject) elems[i]) && !WorkspaceModelManager.isBinaryProject((IProject) elems[i])) >+ fSelectedModels.add(elems[i]); >+ } >+ } >+ >+ //Get all models (workspace and external) excluding fragment models >+ IPluginModelBase[] pluginModels = PluginRegistry.getAllModels(false); >+ monitor.beginTask(PDEUIMessages.GetNonExternalizedStringsOperation_taskMessage, pluginModels.length); >+ >+ //Populate list to an InternationalizeModelTable >+ fModelPluginTable = new InternationalizeModelTable(); >+ for (int i = 0; i < pluginModels.length; i++) { >+ fModelPluginTable.addToModelTable(pluginModels[i], pluginModels[i].getUnderlyingResource() != null ? selected(pluginModels[i].getUnderlyingResource().getProject()) : false); >+ } >+ } >+ >+ /** >+ * >+ * @return whether or not the operation was cancelled >+ */ >+ public boolean wasCanceled() { >+ return fCanceled; >+ } >+ >+ /** >+ * >+ * @param project >+ * @return whether or not the project was preselected >+ */ >+ public boolean selected(IProject project) { >+ return fSelectedModels.contains(project); >+ } >+ >+ /** >+ * >+ * @return the InternationalizeModelTable containing the plug-ins >+ */ >+ public InternationalizeModelTable getPluginTable() { >+ return fModelPluginTable; >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardPluginPage.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardPluginPage.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardPluginPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeWizardPluginPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,653 @@ >+/** >+ * >+ */ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.util.*; >+import java.util.List; >+import java.util.regex.Pattern; >+import org.eclipse.core.runtime.*; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.*; >+import org.eclipse.jface.wizard.IWizardContainer; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.pde.core.IModelProviderEvent; >+import org.eclipse.pde.core.IModelProviderListener; >+import org.eclipse.pde.core.plugin.*; >+import org.eclipse.pde.internal.core.ClasspathUtilCore; >+import org.eclipse.pde.internal.core.PDECore; >+import org.eclipse.pde.internal.core.util.PatternConstructor; >+import org.eclipse.pde.internal.ui.*; >+import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; >+import org.eclipse.pde.internal.ui.util.SWTUtil; >+import org.eclipse.pde.internal.ui.wizards.ListUtil; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.ScrolledComposite; >+import org.eclipse.swt.events.*; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.*; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.progress.WorkbenchJob; >+ >+/** >+ * The first page of the InternationalizeWizard. This page allows the user to >+ * select the desired plug-ins for internationalization. These could be plug-ins >+ * in the user's workspace or external ones. >+ * >+ * @author Team Azure >+ * >+ */ >+public class InternationalizeWizardPluginPage extends WizardPage implements IModelProviderListener { >+ >+ public static final String PAGE_NAME = "InternationalizeWizardPluginPage"; //$NON-NLS-1$ >+ >+ protected IPluginModelBase[] fModels = new IPluginModelBase[0]; >+ //private String fLocation; >+ >+ private boolean fRefreshNeeded = true; >+ >+ private Label fCountLabel; //Displays "x out of y selected" >+ >+ private TableViewer fAvailableListViewer; //All available plug-ins >+ protected TableViewer fSelectedListViewer; //Selected plug-ins >+ >+ private WorkbenchJob fFilterJob; >+ private Text fFilterText; >+ private AvailableFilter fFilter; >+ >+ // Used to track the selection in a HashMap so as to filter >+ // selected items out of the available item list >+ private HashMap fSelected; >+ >+ // Used to block the selection listeners from updating button enablement >+ // when programatically removing items >+ private boolean fBlockSelectionListeners; >+ private Button fAddButton; >+ private Button fAddAllButton; >+ private Button fRemoveButton; >+ private Button fRemoveAllButton; >+ >+ // Used to store the plug-ins >+ private InternationalizeModelTable fInternationalizeModelTable; >+ >+ private class AvailableFilter extends ViewerFilter { >+ private Pattern fPattern; >+ >+ public AvailableFilter() { >+ setPattern("*"); //$NON-NLS-1$ >+ } >+ >+ public boolean select(Viewer viewer, Object parentElement, Object element) { >+ // filter out any items that are currently selected >+ // on a full refresh, these will have been added back to the list >+ if (fSelected.containsKey(element)) >+ return false; >+ if (!(element instanceof IPluginModelBase)) >+ return false; >+ >+ String itemID = ((IPluginModelBase) element).getPluginBase().getId(); >+ if (fPattern.matcher(itemID).matches()) >+ return true; >+ return false; >+ } >+ >+ public boolean setPattern(String newPattern) { >+ if (!newPattern.endsWith("*")) //$NON-NLS-1$ >+ newPattern += "*"; //$NON-NLS-1$ >+ if (!newPattern.startsWith("*")) //$NON-NLS-1$ >+ newPattern = "*" + newPattern; //$NON-NLS-1$ >+ if (fPattern != null) { >+ String oldPattern = fPattern.pattern(); >+ if (newPattern.equals(oldPattern)) >+ return false; >+ } >+ fPattern = PatternConstructor.createPattern(newPattern, true); >+ return true; >+ } >+ } >+ >+ private class ContentProvider extends DefaultContentProvider implements IStructuredContentProvider { >+ /** >+ * @return the list of available non-selected plug-ins >+ */ >+ public Object[] getElements(Object parent) { >+ return fInternationalizeModelTable.getModels(); >+ } >+ } >+ >+ private class SelectedContentProvider extends DefaultContentProvider implements IStructuredContentProvider { >+ /** >+ * @return the list of selected plug-ins >+ */ >+ public Object[] getElements(Object parent) { >+ return fInternationalizeModelTable.getPreSelected(); >+ } >+ } >+ >+ public InternationalizeWizardPluginPage(InternationalizeModelTable modelTable, String pageName) { >+ >+ super(pageName); >+ setTitle(PDEUIMessages.InternationalizeWizard_PluginPage_pageTitle); >+ setDescription(PDEUIMessages.InternationalizeWizard_PluginPage_pageDescription); >+ >+ PDEPlugin.getDefault().getLabelProvider().connect(this); >+ PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this); >+ >+ fInternationalizeModelTable = modelTable; >+ fSelected = new HashMap(); >+ >+ IWizardContainer container = getContainer(); >+ if (container != null) >+ container.updateButtons(); >+ } >+ >+ /** >+ * Adds a filter to the list of available plug-ins >+ */ >+ private void addFilter() { >+ fFilter = new AvailableFilter(); >+ fAvailableListViewer.addFilter(fFilter); >+ fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$ >+ public IStatus runInUIThread(IProgressMonitor monitor) { >+ handleFilter(); >+ return Status.OK_STATUS; >+ } >+ }; >+ fFilterJob.setSystem(true); >+ } >+ >+ /** >+ * Handles changes to the list based on changes to the text field. >+ */ >+ private void handleFilter() { >+ boolean changed = false; >+ String newFilter; >+ if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0) >+ newFilter = "*"; //$NON-NLS-1$ >+ changed = fFilter.setPattern(newFilter); >+ if (changed) { >+ fAvailableListViewer.getTable().setRedraw(false); >+ fAvailableListViewer.refresh(); >+ fAvailableListViewer.getTable().setRedraw(true); >+ updateButtonEnablement(false, false); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) >+ */ >+ public void createControl(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 3; >+ layout.makeColumnsEqualWidth = false; >+ layout.horizontalSpacing = 5; >+ layout.verticalSpacing = 10; >+ container.setLayout(layout); >+ >+ createScrollArea(container); >+ createAvailableList(container).setLayoutData(new GridData(GridData.FILL_BOTH)); >+ createButtonArea(container); >+ createInternationalizeList(container).setLayoutData(new GridData(GridData.FILL_BOTH)); >+ updateCount(); >+ >+ // create container for buttons >+ Composite buttonContainer = new Composite(container, SWT.NONE); >+ buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create()); >+ >+ addViewerListeners(); >+ addFilter(); >+ >+ initialize(); >+ setControl(container); >+ Dialog.applyDialogFont(container); >+ PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE); >+ } >+ >+ /** >+ * >+ * @param parent >+ * @return the container holding the available plug-ins list >+ */ >+ private Composite createAvailableList(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ container.setLayout(layout); >+ container.setLayoutData(new GridData()); >+ >+ Label label = new Label(container, SWT.NONE); >+ label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_availableList); >+ >+ Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); >+ GridData gd = new GridData(GridData.FILL_BOTH); >+ gd.heightHint = 200; >+ gd.widthHint = 225; >+ table.setLayoutData(gd); >+ >+ fAvailableListViewer = new TableViewer(table); >+ fAvailableListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); >+ fAvailableListViewer.setContentProvider(new ContentProvider()); >+ fAvailableListViewer.setInput(PDECore.getDefault().getModelManager()); >+ fAvailableListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); >+ >+ return container; >+ } >+ >+ protected Composite createInternationalizeList(Composite parent) { >+ Composite container = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ container.setLayout(layout); >+ container.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ Label label = new Label(container, SWT.NONE); >+ label.setText(PDEUIMessages.InternationalizeWizard_PluginPage_internationalizeList); >+ >+ Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); >+ GridData gd = new GridData(GridData.FILL_BOTH); >+ gd.widthHint = 225; >+ table.setLayoutData(gd); >+ >+ fSelectedListViewer = new TableViewer(table); >+ fSelectedListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); >+ fSelectedListViewer.setContentProvider(new SelectedContentProvider()); >+ fSelectedListViewer.setInput(PDECore.getDefault().getModelManager().getExternalModelManager()); >+ fSelectedListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); >+ return container; >+ } >+ >+ protected boolean isRefreshNeeded() { >+ if (fRefreshNeeded) { >+ fRefreshNeeded = false; >+ return true; >+ } >+ /*if (fLocation == null) { >+ return true; >+ }*/ >+ return false; >+ } >+ >+ private IPluginModelBase findModel(String id) { >+ for (int i = 0; i < fModels.length; i++) { >+ String modelId = fModels[i].getPluginBase().getId(); >+ if (modelId != null && modelId.equals(id)) >+ return fModels[i]; >+ } >+ return null; >+ } >+ >+ private IFragmentModel[] findFragments(IPlugin plugin) { >+ ArrayList result = new ArrayList(); >+ for (int i = 0; i < fModels.length; i++) { >+ if (fModels[i] instanceof IFragmentModel) { >+ IFragment fragment = ((IFragmentModel) fModels[i]).getFragment(); >+ if (plugin.getId().equalsIgnoreCase(fragment.getPluginId())) { >+ result.add(fModels[i]); >+ } >+ } >+ } >+ return (IFragmentModel[]) result.toArray(new IFragmentModel[result.size()]); >+ } >+ >+ protected void addPluginAndDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) { >+ >+ boolean containsVariable = false; >+ if (!selected.contains(model)) { >+ selected.add(model); >+ boolean hasextensibleAPI = ClasspathUtilCore.hasExtensibleAPI(model); >+ if (!addFragments && !hasextensibleAPI && model instanceof IPluginModel) { >+ IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); >+ for (int i = 0; i < libraries.length; i++) { >+ if (ClasspathUtilCore.containsVariables(libraries[i].getName())) { >+ containsVariable = true; >+ break; >+ } >+ } >+ } >+ addDependencies(model, selected, addFragments || containsVariable || hasextensibleAPI); >+ } >+ } >+ >+ protected void addDependencies(IPluginModelBase model, ArrayList selected, boolean addFragments) { >+ >+ IPluginImport[] required = model.getPluginBase().getImports(); >+ if (required.length > 0) { >+ for (int i = 0; i < required.length; i++) { >+ IPluginModelBase found = findModel(required[i].getId()); >+ if (found != null) { >+ addPluginAndDependencies(found, selected, addFragments); >+ } >+ } >+ } >+ >+ if (addFragments) { >+ if (model instanceof IPluginModel) { >+ IFragmentModel[] fragments = findFragments(((IPluginModel) model).getPlugin()); >+ for (int i = 0; i < fragments.length; i++) { >+ addPluginAndDependencies(fragments[i], selected, addFragments); >+ } >+ } else { >+ IFragment fragment = ((IFragmentModel) model).getFragment(); >+ IPluginModelBase found = findModel(fragment.getPluginId()); >+ if (found != null) { >+ addPluginAndDependencies(found, selected, addFragments); >+ } >+ } >+ } >+ } >+ >+ public List getModelsToInternationalize() { >+ TableItem[] items = fSelectedListViewer.getTable().getItems(); >+ List result = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ result.add(items[i].getData()); >+ } >+ return result; >+ } >+ >+ public void storeSettings() { >+ IDialogSettings settings = getDialogSettings(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.core.IModelProviderListener#modelsChanged(org.eclipse.pde.core.IModelProviderEvent) >+ */ >+ public void modelsChanged(IModelProviderEvent event) { >+ fRefreshNeeded = true; >+ } >+ >+ private void initialize() { >+ updateButtonEnablement(true, true); >+ setPageComplete(false); >+ } >+ >+ private void addViewerListeners() { >+ fAvailableListViewer.addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ handleAdd(); >+ } >+ }); >+ >+ fSelectedListViewer.addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ handleRemove(); >+ } >+ }); >+ >+ fAvailableListViewer.addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!fBlockSelectionListeners) >+ updateSelectionBasedEnablement(event.getSelection(), true); >+ } >+ }); >+ >+ fSelectedListViewer.addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!fBlockSelectionListeners) >+ updateSelectionBasedEnablement(event.getSelection(), false); >+ } >+ }); >+ >+ fFilterText.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ fFilterJob.cancel(); >+ fFilterJob.schedule(200); >+ } >+ }); >+ >+ } >+ >+ private Composite createButtonArea(Composite parent) { >+ ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = layout.marginHeight = 0; >+ comp.setLayoutData(new GridData(GridData.FILL_VERTICAL)); >+ Composite container = new Composite(comp, SWT.NONE); >+ layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginTop = 50; >+ container.setLayout(layout); >+ GridData gd = new GridData(GridData.FILL_VERTICAL); >+ gd.verticalIndent = 15; >+ container.setLayoutData(gd); >+ >+ fAddButton = new Button(container, SWT.PUSH); >+ fAddButton.setText(PDEUIMessages.ImportWizard_DetailedPage_add); >+ fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fAddButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleAdd(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fAddButton); >+ >+ fAddAllButton = new Button(container, SWT.PUSH); >+ fAddAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_addAll); >+ fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fAddAllButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleAddAll(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fAddAllButton); >+ >+ fRemoveButton = new Button(container, SWT.PUSH); >+ fRemoveButton.setText(PDEUIMessages.ImportWizard_DetailedPage_remove); >+ fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fRemoveButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleRemove(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fRemoveButton); >+ >+ fRemoveAllButton = new Button(container, SWT.PUSH); >+ fRemoveAllButton.setText(PDEUIMessages.ImportWizard_DetailedPage_removeAll); >+ fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ fRemoveAllButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleRemoveAll(); >+ } >+ }); >+ SWTUtil.setButtonDimensionHint(fRemoveAllButton); >+ >+ fCountLabel = new Label(container, SWT.NONE); >+ fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); >+ comp.setContent(container); >+ comp.setMinHeight(250); >+ comp.setExpandHorizontal(true); >+ comp.setExpandVertical(true); >+ return container; >+ } >+ >+ private Composite createScrollArea(Composite parent) { >+ Group container = new Group(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(2, false); >+ layout.marginWidth = layout.marginHeight = 6; >+ container.setLayout(layout); >+ >+ GridData gd = new GridData(GridData.FILL_HORIZONTAL); >+ gd.horizontalSpan = 3; >+ container.setLayoutData(gd); >+ container.setText(PDEUIMessages.InternationalizeWizard_PluginPage_filter); >+ >+ Label filterLabel = new Label(container, SWT.NONE); >+ filterLabel.setText(PDEUIMessages.ImportWizard_DetailedPage_search); >+ >+ fFilterText = new Text(container, SWT.BORDER); >+ fFilterText.setText(""); //$NON-NLS-1$ >+ gd = new GridData(GridData.FILL_HORIZONTAL); >+ fFilterText.setLayoutData(gd); >+ >+ return container; >+ } >+ >+ public void setVisible(boolean visible) { >+ super.setVisible(visible); >+ } >+ >+ protected void refreshPage() { >+ fSelectedListViewer.getTable().removeAll(); >+ fSelected = new HashMap(); >+ fAvailableListViewer.refresh(); >+ pageChanged(); >+ } >+ >+ protected void pageChanged() { >+ pageChanged(false, false); >+ } >+ >+ protected void pageChanged(boolean doAddEnablement, boolean doRemoveEnablement) { >+ updateCount(); >+ updateButtonEnablement(doAddEnablement, doRemoveEnablement); >+ setPageComplete(fSelectedListViewer.getTable().getItemCount() > 0); >+ } >+ >+ private void updateCount() { >+ 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()}))); >+ fCountLabel.getParent().layout(); >+ } >+ >+ private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) { >+ int availableCount = fAvailableListViewer.getTable().getItemCount(); >+ int importCount = fSelectedListViewer.getTable().getItemCount(); >+ >+ if (doAddEnablement) >+ updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true); >+ if (doRemoveEnablement) >+ updateSelectionBasedEnablement(fSelectedListViewer.getSelection(), false); >+ >+ fAddAllButton.setEnabled(availableCount > 0); >+ fRemoveAllButton.setEnabled(importCount > 0); >+ } >+ >+ private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) { >+ if (available) >+ fAddButton.setEnabled(!theSelection.isEmpty()); >+ else >+ fRemoveButton.setEnabled(!theSelection.isEmpty()); >+ } >+ >+ private void handleAdd() { >+ IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection(); >+ if (ssel.size() > 0) { >+ Table table = fAvailableListViewer.getTable(); >+ int index = table.getSelectionIndices()[0]; >+ Object[] selection = ssel.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < selection.length; i++) { >+ doAdd(selection[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); >+ pageChanged(true, false); >+ } >+ } >+ >+ private void handleAddAll() { >+ TableItem[] items = fAvailableListViewer.getTable().getItems(); >+ >+ ArrayList data = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ data.add(items[i].getData()); >+ } >+ if (data.size() > 0) { >+ Object[] datas = data.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < datas.length; i++) { >+ doAdd(datas[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ pageChanged(true, false); >+ } >+ } >+ >+ private void handleRemove() { >+ IStructuredSelection ssel = (IStructuredSelection) fSelectedListViewer.getSelection(); >+ if (ssel.size() > 0) { >+ Table table = fSelectedListViewer.getTable(); >+ int index = table.getSelectionIndices()[0]; >+ Object[] selection = ssel.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < selection.length; i++) { >+ doRemove(selection[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); >+ pageChanged(false, true); >+ } >+ } >+ >+ private void doAdd(Object o) { >+ fInternationalizeModelTable.removeModel(o); >+ fSelectedListViewer.add(o); >+ fAvailableListViewer.remove(o); >+ fSelected.put(o, null); >+ } >+ >+ private void doRemove(Object o) { >+ fInternationalizeModelTable.addModel(o); >+ fSelected.remove(o); >+ fSelectedListViewer.remove(o); >+ fAvailableListViewer.add(o); >+ } >+ >+ // used to prevent flicker during operations that move items between lists >+ private void setRedraw(boolean redraw) { >+ fAvailableListViewer.getTable().setRedraw(redraw); >+ fSelectedListViewer.getTable().setRedraw(redraw); >+ } >+ >+ private void handleRemoveAll() { >+ TableItem[] items = fSelectedListViewer.getTable().getItems(); >+ >+ ArrayList data = new ArrayList(); >+ for (int i = 0; i < items.length; i++) { >+ data.add(items[i].getData()); >+ } >+ if (data.size() > 0) { >+ Object[] datas = data.toArray(); >+ setBlockSelectionListeners(true); >+ setRedraw(false); >+ for (int i = 0; i < datas.length; i++) { >+ doRemove(datas[i]); >+ } >+ setRedraw(true); >+ setBlockSelectionListeners(false); >+ pageChanged(false, true); >+ } >+ } >+ >+ public void dispose() { >+ PDEPlugin.getDefault().getLabelProvider().disconnect(this); >+ PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this); >+ } >+ >+ private void setBlockSelectionListeners(boolean blockSelectionListeners) { >+ fBlockSelectionListeners = blockSelectionListeners; >+ } >+ >+ public boolean isCurrentPage() { >+ return super.isCurrentPage(); >+ } >+ >+ public boolean canFlipToNextPage() { >+ if (fSelectedListViewer.getTable().getItems().length > 0) { >+ return true; >+ } >+ return false; >+ } >+} >Index: src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java >diff -N src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/nls/InternationalizeModelTable.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,91 @@ >+package org.eclipse.pde.internal.ui.nls; >+ >+import java.util.ArrayList; >+ >+/** >+ * >+ * Stores the list of BundlePluginModels and ExternalPluginModels to be passed to the >+ * InternationalizeWizard. This class could also used to populate the list of locales >+ * to which plug-ins will be internationalized. >+ * >+ * @author Team Azure >+ * >+ */ >+public class InternationalizeModelTable { >+ private ArrayList fModels; >+ private ArrayList fPreSelected; //Models preselected by the user >+ >+ public InternationalizeModelTable() { >+ fModels = new ArrayList(); >+ fPreSelected = new ArrayList(); >+ } >+ >+ /** >+ * Adds the model to the model table. Takes into consideration the specified >+ * selection. >+ * @param model >+ * @param selected >+ */ >+ public void addToModelTable(Object model, boolean selected) { >+ if (selected) >+ fPreSelected.add(model); >+ else >+ fModels.add(model); >+ } >+ >+ /** >+ * Adds the model to the model table. >+ * @param model >+ */ >+ public void addModel(Object model) { >+ fModels.add(model); >+ } >+ >+ /** >+ * Removes the specified model from the model table. >+ * @param model >+ */ >+ public void removeModel(Object model) { >+ fModels.remove(model); >+ } >+ >+ /** >+ * >+ * @return the number of models in the table >+ */ >+ public int getModelCount() { >+ return fPreSelected.size() + fModels.size(); >+ } >+ >+ /** >+ * Returns the list of models stored in the model table >+ * @return the array of models >+ */ >+ public Object[] getModels() { >+ return fModels.toArray(); >+ } >+ >+ /** >+ * Returns the list of preselected models stored in the model table >+ * @return the array of preselected models >+ */ >+ public Object[] getPreSelected() { >+ return fPreSelected.toArray(); >+ } >+ >+ /** >+ * >+ * @return whether or not the model table contains preselected models >+ */ >+ public boolean hasPreSelected() { >+ return fPreSelected.size() > 0; >+ } >+ >+ /** >+ * >+ * @return whether or not the list of models is empty >+ */ >+ public boolean isEmpty() { >+ return fModels.size() == 0; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 201998
:
86531
|
86640
|
90235
|
90711
|
90764
|
91762
|
93695
|
95610
|
116831