Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,6 +18,7 @@
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.util.Optional;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand All @@ -27,8 +28,11 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
Expand All @@ -42,8 +46,11 @@
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.IShowInTarget;
import org.eclipse.ui.part.ShowInContext;

public class EditorUtilities {

Expand Down Expand Up @@ -284,4 +291,17 @@ public static void openImage(String value, String definingPluginId) {
}
}

public static void showInPackageExplorer(IPackageFragment fragment) {
showPackageExplorer().map(p -> p.getAdapter(IShowInTarget.class))
.ifPresent(show -> show.show(new ShowInContext(null, new StructuredSelection(fragment))));
}


private static Optional<IViewPart> showPackageExplorer() {
try {
return Optional.of(PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES));
} catch (PartInitException e) {
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2024 IBM Corporation and others.
* Copyright (c) 2005, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -31,9 +31,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.actions.FindReferencesAction;
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
Expand Down Expand Up @@ -63,6 +61,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.pde.internal.ui.editor.EditorUtilities;
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
import org.eclipse.pde.internal.ui.editor.TableSection;
Expand All @@ -79,8 +78,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.forms.widgets.FormToolkit;
Expand Down Expand Up @@ -357,16 +354,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
return null;
}

private void handleGoToPackage(ISelection selection) {
IPackageFragment frag = getPackageFragment(selection);
if (frag != null) {
try {
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
action.run(frag);
} catch (PartInitException e) {
}
}
private void handleGoToPackage(IStructuredSelection selection) {
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2018 IBM Corporation and others.
* Copyright (c) 2005, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import org.eclipse.core.resources.IProject;
Expand All @@ -31,7 +32,6 @@
import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.actions.FindReferencesInWorkingSetAction;
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
Expand Down Expand Up @@ -76,6 +76,7 @@
import org.eclipse.pde.internal.ui.PDELabelProvider;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.editor.EditorUtilities;
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
import org.eclipse.pde.internal.ui.editor.TableSection;
Expand All @@ -93,10 +94,8 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.forms.widgets.FormToolkit;
Expand Down Expand Up @@ -414,16 +413,8 @@ private IPackageFragment getPackageFragment(ISelection sel) {
return null;
}

private void handleGoToPackage(ISelection selection) {
IPackageFragment frag = getPackageFragment(selection);
if (frag != null) {
try {
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
action.run(frag);
} catch (PartInitException e) {
}
}
private void handleGoToPackage(IStructuredSelection selection) {
Optional.ofNullable(getPackageFragment(selection)).ifPresent(EditorUtilities::showInPackageExplorer);
}

private void handleOpenProperties() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
* Copyright (c) 2006, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,16 +13,13 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.editor.text;

import java.util.Optional;

import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.actions.ShowInPackageViewAction;
import org.eclipse.jface.text.IRegion;
import org.eclipse.pde.internal.core.text.bundle.BasePackageHeader;
import org.eclipse.pde.internal.core.util.PDEJavaHelper;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.pde.internal.ui.editor.EditorUtilities;

public class PackageHyperlink extends ManifestElementHyperlink {

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

@Override
protected void open2() {
IResource res = fHeader.getBundle().getModel().getUnderlyingResource();
if (res == null) {
return;
}
IPackageFragment frag = PDEJavaHelper.getPackageFragment(fElement, null, res.getProject());
if (frag == null) {
return;
}
try {
IViewPart part = PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
ShowInPackageViewAction action = new ShowInPackageViewAction(part.getSite());
action.run(frag);
} catch (PartInitException e) {
PDEPlugin.logException(e);
}
Optional.ofNullable(fHeader.getBundle().getModel().getUnderlyingResource()).map(IResource::getProject)
.map(p -> PDEJavaHelper.getPackageFragment(fElement, null, p))
.ifPresent(EditorUtilities::showInPackageExplorer);
}

}
Loading