Skip to content

Commit

Permalink
Files not present in branch but changes are visible in github commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lathapatil committed Oct 22, 2024
1 parent 204c26f commit aeb906f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui;

import java.util.HashMap;
import java.util.Locale;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -86,6 +87,7 @@
import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
import org.eclipse.pde.internal.core.text.bundle.PackageObject;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.eclipse.pde.internal.ui.dialogs.PluginSelectionDialog;
import org.eclipse.pde.internal.ui.elements.NamedElement;
import org.eclipse.pde.internal.ui.util.SWTUtil;
import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
Expand All @@ -96,6 +98,11 @@

public class PDELabelProvider extends SharedLabelProvider {
private static final String SYSTEM_BUNDLE = "system.bundle"; //$NON-NLS-1$
private IPluginModelBase currentModel;

public IPluginModelBase getCurrentPluginModel() {
return currentModel;
}

public PDELabelProvider() {
}
Expand Down Expand Up @@ -203,6 +210,13 @@ public String getObjectText(IPluginBase pluginBase) {
}
if (pluginBase.getModel() != null && !pluginBase.getModel().isInSync())
text += " " + PDEUIMessages.PluginModelManager_outOfSync; //$NON-NLS-1$

HashMap<String, Boolean> existingImports = PluginSelectionDialog.getExistingImports(currentModel, false);
if (existingImports.get(pluginBase.getId()) != null && existingImports.get(pluginBase.getId())) {
text += " " + PDEUIMessages.PluginModelManager_alreadyAddedViaReexport; //$NON-NLS-1$
} else if (existingImports.get(pluginBase.getId()) != null && !existingImports.get(pluginBase.getId())) {
text += " " + PDEUIMessages.PluginModelManager_alreadyAdded; //$NON-NLS-1$
}
return text;
}

Expand Down Expand Up @@ -952,4 +966,7 @@ public static String formatVersion(String versionRange) {
return versionRange;
}

public void setCurrentModel(IPluginModelBase currentModel) {
this.currentModel = currentModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
public class PDEUIMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.pde.internal.ui.pderesources";//$NON-NLS-1$

public static String PluginModelManager_alreadyImported;

public static String PluginModelManager_alreadyAdded;

public static String PluginModelManager_alreadyAddedViaReexport;

public static String PluginModelManager_alreadyExported;

public static String AbstractLauncherToolbar_noProblems;

public static String AbstractLauncherToolbar_noSelection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.pde.core.plugin.IFragment;
import org.eclipse.pde.core.plugin.IFragmentModel;
Expand All @@ -42,6 +42,7 @@
import org.eclipse.pde.internal.ui.IHelpContextIds;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -137,6 +138,11 @@ public PluginSelectionDialog(Shell parentShell, IPluginModelBase[] models, boole
setListLabelProvider(PDEPlugin.getDefault().getLabelProvider());
}

public PluginSelectionDialog(Shell activeWorkbenchShell, IPluginModelBase[] availablePlugins,
boolean multipleSelection, IPluginModelBase model) {
this(activeWorkbenchShell, availablePlugins, multipleSelection);
PDEPlugin.getDefault().getLabelProvider().setCurrentModel(model);
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
Expand All @@ -153,8 +159,8 @@ private static IPluginModelBase[] getElements(boolean includeFragments) {
return PluginRegistry.getActiveModels(includeFragments);
}

public static HashSet<String> getExistingImports(IPluginModelBase model, boolean includeImportPkg) {
HashSet<String> existingImports = new HashSet<>();
public static HashMap<String, Boolean> getExistingImports(IPluginModelBase model, boolean includeImportPkg) {
HashMap<String, Boolean> existingImports = new HashMap<>();
addSelfAndDirectImports(existingImports, model);
if (model instanceof IFragmentModel) {
IFragment fragment = ((IFragmentModel) model).getFragment();
Expand All @@ -169,33 +175,34 @@ public static HashSet<String> getExistingImports(IPluginModelBase model, boolean
return existingImports;
}

private static void addSelfAndDirectImports(HashSet<String> set, IPluginModelBase model) {
private static void addSelfAndDirectImports(HashMap<String, Boolean> existingImports, IPluginModelBase model) {
if (model == null) {
return;
}
set.add(model.getPluginBase().getId());
existingImports.put(model.getPluginBase().getId(), false);
IPluginImport[] imports = model.getPluginBase().getImports();
for (IPluginImport pImport : imports) {
String id = pImport.getId();
if (set.add(id)) {
addReexportedImport(set, id);
}
existingImports.put(id, false);
addReexportedImport(existingImports, id);

}
}

private static void addReexportedImport(HashSet<String> set, String id) {
private static void addReexportedImport(HashMap<String, Boolean> existingImports, String id) {
IPluginModelBase model = PluginRegistry.findModel(id);
if (model != null) {
IPluginImport[] imports = model.getPluginBase().getImports();
for (IPluginImport pImport : imports) {
if (pImport.isReexported() && set.add(pImport.getId())) {
addReexportedImport(set, pImport.getId());
if (pImport.isReexported()) {
existingImports.put(pImport.getId(), true);
addReexportedImport(existingImports, pImport.getId());
}
}
}
}

private static void addImportedPackages(IBundlePluginModelBase base, HashSet<String> existingImports) {
private static void addImportedPackages(IBundlePluginModelBase base, HashMap<String, Boolean> existingImports) {
HashMap<String, ImportPackageObject> map = getImportPackages(base);
if (map == null) {
return;
Expand All @@ -221,7 +228,7 @@ private static void addImportedPackages(IBundlePluginModelBase base, HashSet<Str
continue;
}
}
existingImports.add(exported[i].getSupplier().getSymbolicName());
existingImports.put(exported[i].getSupplier().getSymbolicName(), false);
}
}
}
Expand Down Expand Up @@ -298,4 +305,22 @@ protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

}
@Override
protected void updateButtonsEnableState(IStatus status) {
super.updateButtonsEnableState(status);
Button okButton = getOkButton();
StructuredSelection currentSelection = super.getSelectedItems();
HashMap<String, Boolean> existingImports = PluginSelectionDialog
.getExistingImports(PDEPlugin.getDefault().getLabelProvider().getCurrentPluginModel(), false);
if (!currentSelection.isEmpty())
okButton.setEnabled(false);
for (Object selection : currentSelection) {
if (selection instanceof IPluginModelBase
&& !(existingImports.keySet().contains(((IPluginModelBase) selection).getPluginBase().getId()))) {
okButton.setEnabled(true);
break;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ UpdateManager_op_change= Property Change
########################################################

PluginModelManager_outOfSync = (out of sync)
PluginModelManager_alreadyImported = [already imported]
PluginModelManager_alreadyAdded = [already added]
PluginModelManager_alreadyAddedViaReexport = [already added via re-export]
PluginModelManager_alreadyExported = [already exported]

###### Status text #####################################
ExportDestinationTab_InstallIntoCurrentPlatform=&Install into host. Repository:
Expand Down

0 comments on commit aeb906f

Please sign in to comment.