Skip to content

Commit b03463f

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

4 files changed

Lines changed: 41 additions & 52 deletions

File tree

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

Lines changed: 22 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
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* see git history
1314
*******************************************************************************/
1415
package org.eclipse.pde.internal.ui.editor;
1516

@@ -18,6 +19,7 @@
1819
import java.io.InputStream;
1920
import java.net.URI;
2021
import java.nio.file.Files;
22+
import java.util.Optional;
2123

2224
import org.eclipse.core.resources.IContainer;
2325
import org.eclipse.core.resources.IFile;
@@ -27,8 +29,11 @@
2729
import org.eclipse.core.runtime.CoreException;
2830
import org.eclipse.core.runtime.IPath;
2931
import org.eclipse.core.runtime.URIUtil;
32+
import org.eclipse.jdt.core.IPackageFragment;
33+
import org.eclipse.jdt.ui.JavaUI;
3034
import org.eclipse.jface.dialogs.IMessageProvider;
3135
import org.eclipse.jface.dialogs.MessageDialog;
36+
import org.eclipse.jface.viewers.StructuredSelection;
3237
import org.eclipse.osgi.util.NLS;
3338
import org.eclipse.pde.core.plugin.IPluginModelBase;
3439
import org.eclipse.pde.core.plugin.PluginRegistry;
@@ -42,8 +47,11 @@
4247
import org.eclipse.swt.SWTException;
4348
import org.eclipse.swt.graphics.ImageData;
4449
import org.eclipse.swt.graphics.ImageLoader;
50+
import org.eclipse.ui.IViewPart;
4551
import org.eclipse.ui.PartInitException;
4652
import org.eclipse.ui.ide.IDE;
53+
import org.eclipse.ui.part.IShowInTarget;
54+
import org.eclipse.ui.part.ShowInContext;
4755

4856
public class EditorUtilities {
4957

@@ -284,4 +292,17 @@ public static void openImage(String value, String definingPluginId) {
284292
}
285293
}
286294

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

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

Lines changed: 5 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
@@ -14,6 +14,7 @@
1414
* Joern Dinkla <devnull@dinkla.com> - bug 200757
1515
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 487988
1616
* Martin Karpisek <martin.karpisek@gmail.com> - Bug 351356
17+
* see git history
1718
*******************************************************************************/
1819

1920
package org.eclipse.pde.internal.ui.editor.plugin;
@@ -31,9 +32,7 @@
3132
import org.eclipse.jdt.core.JavaCore;
3233
import org.eclipse.jdt.core.JavaModelException;
3334
import org.eclipse.jdt.ui.JavaElementLabelProvider;
34-
import org.eclipse.jdt.ui.JavaUI;
3535
import org.eclipse.jdt.ui.actions.FindReferencesAction;
36-
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
3736
import org.eclipse.jface.action.Action;
3837
import org.eclipse.jface.action.IMenuManager;
3938
import org.eclipse.jface.action.Separator;
@@ -63,6 +62,7 @@
6362
import org.eclipse.pde.internal.ui.IHelpContextIds;
6463
import org.eclipse.pde.internal.ui.PDEPlugin;
6564
import org.eclipse.pde.internal.ui.PDEUIMessages;
65+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
6666
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
6767
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
6868
import org.eclipse.pde.internal.ui.editor.TableSection;
@@ -79,8 +79,6 @@
7979
import org.eclipse.swt.widgets.Composite;
8080
import org.eclipse.swt.widgets.Display;
8181
import org.eclipse.swt.widgets.Table;
82-
import org.eclipse.ui.IViewPart;
83-
import org.eclipse.ui.PartInitException;
8482
import org.eclipse.ui.PlatformUI;
8583
import org.eclipse.ui.actions.ActionFactory;
8684
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -357,16 +355,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
357355
return null;
358356
}
359357

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-
}
358+
private void handleGoToPackage(IStructuredSelection selection) {
359+
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
370360
}
371361

372362
@Override

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

Lines changed: 6 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
@@ -12,11 +12,13 @@
1212
* IBM Corporation - initial API and implementation
1313
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 487988
1414
* Martin Karpisek <martin.karpisek@gmail.com> - Bug 351356
15+
* see git history
1516
*******************************************************************************/
1617
package org.eclipse.pde.internal.ui.editor.plugin;
1718

1819
import java.util.ArrayList;
1920
import java.util.HashSet;
21+
import java.util.Optional;
2022
import java.util.Set;
2123

2224
import org.eclipse.core.resources.IProject;
@@ -31,7 +33,6 @@
3133
import org.eclipse.jdt.ui.ISharedImages;
3234
import org.eclipse.jdt.ui.JavaUI;
3335
import org.eclipse.jdt.ui.actions.FindReferencesInWorkingSetAction;
34-
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
3536
import org.eclipse.jface.action.Action;
3637
import org.eclipse.jface.action.IMenuManager;
3738
import org.eclipse.jface.action.Separator;
@@ -76,6 +77,7 @@
7677
import org.eclipse.pde.internal.ui.PDELabelProvider;
7778
import org.eclipse.pde.internal.ui.PDEPlugin;
7879
import org.eclipse.pde.internal.ui.PDEUIMessages;
80+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
7981
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
8082
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
8183
import org.eclipse.pde.internal.ui.editor.TableSection;
@@ -93,10 +95,8 @@
9395
import org.eclipse.swt.widgets.Composite;
9496
import org.eclipse.swt.widgets.Display;
9597
import org.eclipse.swt.widgets.Table;
96-
import org.eclipse.ui.IViewPart;
9798
import org.eclipse.ui.IWorkingSet;
9899
import org.eclipse.ui.IWorkingSetManager;
99-
import org.eclipse.ui.PartInitException;
100100
import org.eclipse.ui.PlatformUI;
101101
import org.eclipse.ui.actions.ActionFactory;
102102
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -414,16 +414,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
414414
return null;
415415
}
416416

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-
}
417+
private void handleGoToPackage(IStructuredSelection selection) {
418+
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
427419
}
428420

429421
private void handleOpenProperties() {
Lines changed: 8 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
@@ -10,19 +10,17 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* see git history
1314
*******************************************************************************/
1415
package org.eclipse.pde.internal.ui.editor.text;
1516

17+
import java.util.Optional;
18+
1619
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;
2020
import org.eclipse.jface.text.IRegion;
2121
import org.eclipse.pde.internal.core.text.bundle.BasePackageHeader;
2222
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;
23+
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
2624

2725
public class PackageHyperlink extends ManifestElementHyperlink {
2826

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

3634
@Override
3735
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-
}
36+
Optional.ofNullable(fHeader.getBundle().getModel().getUnderlyingResource()).map(IResource::getProject)
37+
.map(p -> PDEJavaHelper.getPackageFragment(fElement, null, p))
38+
.ifPresent(EditorUtilities::showInPackageExplorer);
5339
}
5440

5541
}

0 commit comments

Comments
 (0)