Skip to content

Commit a3a70c3

Browse files
committed
Avoid deprecated org.eclipse.jdt.ui.actions.ShowInPackageViewAction
1 parent 3993065 commit a3a70c3

4 files changed

Lines changed: 37 additions & 52 deletions

File tree

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/EditorUtilities.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2008 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,6 +18,7 @@
1818
import java.io.InputStream;
1919
import java.net.URI;
2020
import java.nio.file.Files;
21+
import java.util.Optional;
2122

2223
import org.eclipse.core.resources.IContainer;
2324
import org.eclipse.core.resources.IFile;
@@ -27,8 +28,11 @@
2728
import org.eclipse.core.runtime.CoreException;
2829
import org.eclipse.core.runtime.IPath;
2930
import org.eclipse.core.runtime.URIUtil;
31+
import org.eclipse.jdt.core.IPackageFragment;
32+
import org.eclipse.jdt.ui.JavaUI;
3033
import org.eclipse.jface.dialogs.IMessageProvider;
3134
import org.eclipse.jface.dialogs.MessageDialog;
35+
import org.eclipse.jface.viewers.StructuredSelection;
3236
import org.eclipse.osgi.util.NLS;
3337
import org.eclipse.pde.core.plugin.IPluginModelBase;
3438
import org.eclipse.pde.core.plugin.PluginRegistry;
@@ -42,8 +46,11 @@
4246
import org.eclipse.swt.SWTException;
4347
import org.eclipse.swt.graphics.ImageData;
4448
import org.eclipse.swt.graphics.ImageLoader;
49+
import org.eclipse.ui.IViewPart;
4550
import org.eclipse.ui.PartInitException;
4651
import org.eclipse.ui.ide.IDE;
52+
import org.eclipse.ui.part.IShowInTarget;
53+
import org.eclipse.ui.part.ShowInContext;
4754

4855
public class EditorUtilities {
4956

@@ -284,4 +291,17 @@ public static void openImage(String value, String definingPluginId) {
284291
}
285292
}
286293

294+
public static void showInPackageExplorer(IPackageFragment fragment) {
295+
showPackageExplorer().map(p -> p.getAdapter(IShowInTarget.class))
296+
.ifPresent(show -> show.show(new ShowInContext(null, new StructuredSelection(fragment))));
297+
}
298+
299+
300+
private static Optional<IViewPart> showPackageExplorer() {
301+
try {
302+
return Optional.of(PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES));
303+
} catch (PartInitException e) {
304+
return Optional.empty();
305+
}
306+
}
287307
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageSection.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2024 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -31,9 +31,7 @@
3131
import org.eclipse.jdt.core.JavaCore;
3232
import org.eclipse.jdt.core.JavaModelException;
3333
import org.eclipse.jdt.ui.JavaElementLabelProvider;
34-
import org.eclipse.jdt.ui.JavaUI;
3534
import org.eclipse.jdt.ui.actions.FindReferencesAction;
36-
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
3735
import org.eclipse.jface.action.Action;
3836
import org.eclipse.jface.action.IMenuManager;
3937
import org.eclipse.jface.action.Separator;
@@ -63,6 +61,7 @@
6361
import org.eclipse.pde.internal.ui.IHelpContextIds;
6462
import org.eclipse.pde.internal.ui.PDEPlugin;
6563
import org.eclipse.pde.internal.ui.PDEUIMessages;
64+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
6665
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
6766
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
6867
import org.eclipse.pde.internal.ui.editor.TableSection;
@@ -79,8 +78,6 @@
7978
import org.eclipse.swt.widgets.Composite;
8079
import org.eclipse.swt.widgets.Display;
8180
import org.eclipse.swt.widgets.Table;
82-
import org.eclipse.ui.IViewPart;
83-
import org.eclipse.ui.PartInitException;
8481
import org.eclipse.ui.PlatformUI;
8582
import org.eclipse.ui.actions.ActionFactory;
8683
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -357,16 +354,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
357354
return null;
358355
}
359356

360-
private void handleGoToPackage(ISelection selection) {
361-
IPackageFragment frag = getPackageFragment(selection);
362-
if (frag != null) {
363-
try {
364-
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
365-
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
366-
action.run(frag);
367-
} catch (PartInitException e) {
368-
}
369-
}
357+
private void handleGoToPackage(IStructuredSelection selection) {
358+
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
370359
}
371360

372361
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ImportPackageSection.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2018 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,7 @@
1717

1818
import java.util.ArrayList;
1919
import java.util.HashSet;
20+
import java.util.Optional;
2021
import java.util.Set;
2122

2223
import org.eclipse.core.resources.IProject;
@@ -31,7 +32,6 @@
3132
import org.eclipse.jdt.ui.ISharedImages;
3233
import org.eclipse.jdt.ui.JavaUI;
3334
import org.eclipse.jdt.ui.actions.FindReferencesInWorkingSetAction;
34-
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
3535
import org.eclipse.jface.action.Action;
3636
import org.eclipse.jface.action.IMenuManager;
3737
import org.eclipse.jface.action.Separator;
@@ -76,6 +76,7 @@
7676
import org.eclipse.pde.internal.ui.PDELabelProvider;
7777
import org.eclipse.pde.internal.ui.PDEPlugin;
7878
import org.eclipse.pde.internal.ui.PDEUIMessages;
79+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
7980
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
8081
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
8182
import org.eclipse.pde.internal.ui.editor.TableSection;
@@ -93,10 +94,8 @@
9394
import org.eclipse.swt.widgets.Composite;
9495
import org.eclipse.swt.widgets.Display;
9596
import org.eclipse.swt.widgets.Table;
96-
import org.eclipse.ui.IViewPart;
9797
import org.eclipse.ui.IWorkingSet;
9898
import org.eclipse.ui.IWorkingSetManager;
99-
import org.eclipse.ui.PartInitException;
10099
import org.eclipse.ui.PlatformUI;
101100
import org.eclipse.ui.actions.ActionFactory;
102101
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -414,16 +413,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
414413
return null;
415414
}
416415

417-
private void handleGoToPackage(ISelection selection) {
418-
IPackageFragment frag = getPackageFragment(selection);
419-
if (frag != null) {
420-
try {
421-
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
422-
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
423-
action.run(frag);
424-
} catch (PartInitException e) {
425-
}
426-
}
416+
private void handleGoToPackage(IStructuredSelection selection) {
417+
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
427418
}
428419

429420
private void handleOpenProperties() {
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2015 IBM Corporation and others.
2+
* Copyright (c) 2006, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,16 +13,13 @@
1313
*******************************************************************************/
1414
package org.eclipse.pde.internal.ui.editor.text;
1515

16+
import java.util.Optional;
17+
1618
import org.eclipse.core.resources.IResource;
17-
import org.eclipse.jdt.core.IPackageFragment;
18-
import org.eclipse.jdt.ui.JavaUI;
19-
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
2019
import org.eclipse.jface.text.IRegion;
2120
import org.eclipse.pde.internal.core.text.bundle.BasePackageHeader;
2221
import org.eclipse.pde.internal.core.util.PDEJavaHelper;
23-
import org.eclipse.pde.internal.ui.PDEPlugin;
24-
import org.eclipse.ui.IViewPart;
25-
import org.eclipse.ui.PartInitException;
22+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
2623

2724
public class PackageHyperlink extends ManifestElementHyperlink {
2825

@@ -35,21 +32,9 @@ public PackageHyperlink(IRegion region, String pack, BasePackageHeader header) {
3532

3633
@Override
3734
protected void open2() {
38-
IResource res = fHeader.getBundle().getModel().getUnderlyingResource();
39-
if (res == null) {
40-
return;
41-
}
42-
IPackageFragment frag = PDEJavaHelper.getPackageFragment(fElement, null, res.getProject());
43-
if (frag == null) {
44-
return;
45-
}
46-
try {
47-
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
48-
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
49-
action.run(frag);
50-
} catch (PartInitException e) {
51-
PDEPlugin.logException(e);
52-
}
35+
Optional.ofNullable(fHeader.getBundle().getModel().getUnderlyingResource()).map(IResource::getProject)
36+
.map(p -> PDEJavaHelper.getPackageFragment(fElement, null, p))
37+
.ifPresent(EditorUtilities::showInPackageExplorer);
5338
}
5439

5540
}

0 commit comments

Comments
 (0)