Skip to content

Commit

Permalink
JBIDE-18359: Fixed regression bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 16, 2014
1 parent 02b08b2 commit 0c880f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
Expand Down Expand Up @@ -113,7 +114,7 @@ public static IStructuredSelection getCurrentSelection(
if (currentSelection == null) {
// Try to get from Project Explorer
currentSelection = (IStructuredSelection) selectionService
.getSelection("org.eclipse.ui.navigator.ProjectExplorer");
.getSelection(IPageLayout.ID_PROJECT_EXPLORER);
}
if (currentSelection == null) {
// Try to get from Navigator View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
Expand All @@ -33,6 +34,7 @@
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
import org.eclipse.rse.ui.view.SystemAdapterHelpers;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
Expand All @@ -41,6 +43,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.jboss.forge.addon.ui.context.UISelection;
import org.jboss.tools.forge.core.util.ProjectTools;
import org.jboss.tools.forge.ui.internal.ForgeUIPlugin;
import org.jboss.tools.forge.ui.internal.ext.context.UIContextImpl;
Expand All @@ -57,33 +60,33 @@ public void onFinish(final UIContextImpl context) {
@Override
public void run() {
importNewProjects();
}
}
});
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
refreshInitialSelection(context);
}
}
});
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
updateProjectConfiguration();
}
}
});
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
showFinalSelection(context);
}
}
});
}

public void onCancel(UIContextImpl context) {
pomFile = null;
pomFileModificationStamp = -1;
}

public void onCreate(UIContextImpl context) {
UISelectionImpl<?> selection = context.getInitialSelection();
if (selection != null) {
Expand All @@ -96,13 +99,13 @@ public void onCreate(UIContextImpl context) {
}
}
}

private void importNewProjects() {
if (ImportEclipseProjectListener.INSTANCE.projectsAvailableForImport()) {
ImportEclipseProjectListener.INSTANCE.doImport();
}
}

private void refreshInitialSelection(UIContextImpl context) {
try {
UISelectionImpl<?> selection = context.getInitialSelection();
Expand All @@ -122,26 +125,26 @@ private void refreshInitialSelection(UIContextImpl context) {
ForgeUIPlugin.log(e);
}
}

private void updateProjectConfiguration() {
if (pomFileModificationStamp != -1 && pomFile != null && pomFile.getModificationStamp() > pomFileModificationStamp) {
ProjectTools.updateProjectConfiguration(pomFile.getProject());
}
pomFile = null;
pomFileModificationStamp = -1;
}

private void showFinalSelection(UIContextImpl context) {
Object object = context.getSelection();
if (object != null) {
selectResourceFor(object);
}
UISelection<?> selection = context.getSelection();
if (selection != null && !selection.isEmpty()) {
selectResourceFor(selection.get());
}
}

private void selectResourceFor(Object object) {
try {
Method method = object.getClass().getMethod(
"getUnderlyingResourceObject",
"getUnderlyingResourceObject",
new Class[] {});
if (method != null) {
Object resource = method.invoke(object, new Object[] {});
Expand Down Expand Up @@ -180,40 +183,40 @@ private void selectFile(File file) {
ForgeUIPlugin.log(e);
}
}

private void expandWorkspaceResource(IResource container) {
IWorkbenchPage workbenchPage = getActiveWorkbenchPage();
if (workbenchPage != null) {
refreshWorkspaceResource(container);
IViewPart projectExplorer = workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
IViewPart projectExplorer = workbenchPage.findView(IPageLayout.ID_PROJECT_EXPLORER);
if (projectExplorer != null && projectExplorer instanceof CommonNavigator) {
expandInProjectExplorer((CommonNavigator)projectExplorer, container);
}
IViewPart packageExplorer = workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
}
IViewPart packageExplorer = workbenchPage.findView(JavaUI.ID_PACKAGES);
if (packageExplorer != null) {
expandInPackageExplorer(packageExplorer, container);
}
}
}

private void refreshWorkspaceResource(IResource container) {
try {
container.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ForgeUIPlugin.log(e);
}
}

private void expandSystemDirectory(IFileStore fileStore) {
IWorkbenchPage workbenchPage = getActiveWorkbenchPage();
IViewPart remoteSystemView = workbenchPage.findView("org.eclipse.rse.ui.view.systemView");
if (remoteSystemView != null) {
expandInRemoteSystemView(remoteSystemView, fileStore);
}
}

private void expandInRemoteSystemView(
IViewPart remoteSystemView,
IViewPart remoteSystemView,
IFileStore fileStore) {
Viewer viewer = getViewer(remoteSystemView);
Object input = viewer.getInput();
Expand Down Expand Up @@ -243,7 +246,7 @@ private void expandInRemoteSystemView(
viewer.setSelection(new StructuredSelection(treePath));
if (viewer instanceof TreeViewer) {
((TreeViewer)viewer).expandToLevel(treePath, 1);

}
}

Expand All @@ -254,7 +257,7 @@ private Viewer getViewer(IViewPart remoteSystemView) {
return null;
}
}

private ArrayList<String> createSegmentNames(IFileStore fileStore) {
ArrayList<String> result = new ArrayList<String>();
while (fileStore.getParent() != null) {
Expand All @@ -267,25 +270,25 @@ private ArrayList<String> createSegmentNames(IFileStore fileStore) {
result.add(0, "Local");
return result;
}

private IWorkbenchPage getActiveWorkbenchPage() {
IWorkbenchPage result = null;
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow != null) {
result = workbenchWindow.getActivePage();
}
if (result != null) {

}
return result;
return result;
}

private void expandInProjectExplorer(CommonNavigator projectExplorer, IResource container) {
projectExplorer.selectReveal(new StructuredSelection(container));
TreeViewer treeViewer = projectExplorer.getCommonViewer();
treeViewer.expandToLevel(container, 1);
}

private void expandInPackageExplorer(IViewPart packageExplorer, IResource container) {
if (packageExplorer instanceof ISetSelectionTarget) {
((ISetSelectionTarget)packageExplorer).selectReveal(new StructuredSelection(container));
Expand All @@ -295,7 +298,7 @@ private void expandInPackageExplorer(IViewPart packageExplorer, IResource contai
((TreeViewer)treeViewer).expandToLevel(JavaCore.create(container), 1);
}
}

private void openFileInEditor(IFileStore fileStore) {
try {
IWorkbenchPage workbenchPage = getActiveWorkbenchPage();
Expand All @@ -315,5 +318,5 @@ private IFile determinePomFile(IResource resource) {
}
return result;
}

}

0 comments on commit 0c880f1

Please sign in to comment.