### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.ui 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 5 Mar 2008 18:16:14 -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 fSelection 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 5 Mar 2008 18:16:14 -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 fExternalizeSelectedPluginsOnly 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, + * fSkipMessageDialog 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.361 diff -u -r1.361 PDEUIMessages.java --- src/org/eclipse/pde/internal/ui/PDEUIMessages.java 5 Mar 2008 15:04:42 -0000 1.361 +++ src/org/eclipse/pde/internal/ui/PDEUIMessages.java 5 Mar 2008 18:16:00 -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.972 diff -u -r1.972 pderesources.properties --- src/org/eclipse/pde/internal/ui/pderesources.properties 5 Mar 2008 15:04:41 -0000 1.972 +++ src/org/eclipse/pde/internal/ui/pderesources.properties 5 Mar 2008 18:16:14 -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.211 diff -u -r1.211 plugin.properties --- plugin.properties 27 Feb 2008 17:17:43 -0000 1.211 +++ plugin.properties 5 Mar 2008 18:15:54 -0000 @@ -249,4 +249,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.438 diff -u -r1.438 plugin.xml --- plugin.xml 5 Mar 2008 16:15:11 -0000 1.438 +++ plugin.xml 5 Mar 2008 18:15:55 -0000 @@ -587,6 +587,13 @@ id="org.eclipse.pde.ui.ExternalizeStrings"> + + - + + + + + 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,198 @@ +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(); + Locale[] availableLocales = Locale.getAvailableLocales(); + for (int i = 0; i < availableLocales.length; i++) { + fInternationalizeLocaleModelTable.addModel(availableLocales[i]); + } + } + + /** + * 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(); + return null; + } + + 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 true; + //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 projects = new ArrayList(); + List pluginModels = getPluginModelsForInternationalization(); + selection = new StructuredSelection(pluginModels); //Save the plug-ins selected for internationalization in a StructuredSelection + + for (Iterator it = pluginModels.iterator(); it.hasNext();) { + IPluginModelBase pluginModel = (IPluginModelBase) it.next(); + //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,92 @@ +package org.eclipse.pde.internal.ui.nls; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * 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 List fModels; + private List 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; + } +}