Skip to content

Commit

Permalink
JBIDE-18223: Forge context is now set to the 'new project location'
Browse files Browse the repository at this point in the history
after 'project-new' command
  • Loading branch information
gastaldi committed Sep 10, 2014
1 parent 97770a1 commit fdaaaf7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.Collection;

import org.apache.maven.model.Model;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand All @@ -19,24 +22,33 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.jboss.tools.forge.ui.internal.ForgeUIPlugin;

/**
* Imports a maven-ized project into the workspace
*
*
* FOR INTERNAL USE ONLY. This class was copied from the
* org.jboss.tools.forge.ui plugin in order to avoid dependency on it and should
* be removed in future versions.
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/
public class ProjectImporter {

Expand Down Expand Up @@ -68,6 +80,14 @@ public void importProject() {
} catch (InterruptedException e) {
ForgeUIPlugin.log(e);
}
// Select created project
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
selectCreatedProject();
}
});

}

private Collection<MavenProjectInfo> getProjectToImport() {
Expand All @@ -91,6 +111,38 @@ private MavenProjectInfo createMavenProjectInfo() {
return result;
}

private void selectCreatedProject() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(moduleLocation);
if (project != null) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (workbenchPage != null) {
IViewPart projectExplorer = workbenchPage
.findView("org.eclipse.ui.navigator.ProjectExplorer");
if (projectExplorer instanceof ISetSelectionTarget) {
((ISetSelectionTarget) projectExplorer)
.selectReveal(new StructuredSelection(project));
}
IViewPart packageExplorer = workbenchPage
.findView(JavaUI.ID_PACKAGES);
if (packageExplorer == null && projectExplorer == null) {
try {
packageExplorer = workbenchPage
.showView(JavaUI.ID_PACKAGES);
} catch (PartInitException e) {
ForgeUIPlugin.log(e);
}
}
if (packageExplorer instanceof ISetSelectionTarget) {
((ISetSelectionTarget) packageExplorer)
.selectReveal(new StructuredSelection(project));
}
}
}
}

private class GeneralImportWorkspaceJob extends WorkspaceJob {

public GeneralImportWorkspaceJob(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
Expand All @@ -35,14 +31,14 @@
import org.jboss.tools.forge.core.runtime.ForgeRuntimeType;

public class ForgeInstallationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

private final int DEFAULT_COLUMN_WIDTH = 350/3 +1;

private CheckboxTableViewer runtimesTableViewer ;
private ArrayList<ForgeRuntime> runtimes = null;
private ForgeRuntime defaultRuntime = null;
private boolean refreshNeeded = false;

public ForgeInstallationsPreferencePage() {
super("Installed Forge Runtimes");
}
Expand All @@ -51,19 +47,19 @@ public void init(IWorkbench workbench) {
}

protected Control createContents(Composite parent) {
noDefaultAndApplyButton();
createLayout(parent);
noDefaultAndApplyButton();
createLayout(parent);
createWrapLabel(parent);
createVerticalSpacer(parent);
createVerticalSpacer(parent);
createPageBody(parent);
initializeForgeInstallations();
initializeForgeInstallations();
return parent;
}

private void createPageBody(Composite parent) {
Composite pageBody = createPageBodyControl(parent);
createTitleLabel(pageBody);
createRuntimesArea(pageBody);
Composite pageBody = createPageBodyControl(parent);
createTitleLabel(pageBody);
createRuntimesArea(pageBody);
}

private void createTitleLabel(Composite parent) {
Expand All @@ -76,14 +72,14 @@ private void createTitleLabel(Composite parent) {
}

private void createRuntimesArea(Composite parent) {
Table runtimesTable = createRuntimesTable(parent);
Table runtimesTable = createRuntimesTable(parent);
createNameColumn(runtimesTable);
createLocationColumn(runtimesTable);
createLocationColumn(runtimesTable);
createRuntimesTableViewer(runtimesTable);
}

private void createRuntimesTableViewer(Table table) {
runtimesTableViewer = new CheckboxTableViewer(table);
runtimesTableViewer = new CheckboxTableViewer(table);
runtimesTableViewer.setLabelProvider(new ForgeInstallationLabelProvider());
runtimesTableViewer.setContentProvider(ArrayContentProvider.getInstance());
runtimesTableViewer.addCheckStateListener(new ICheckStateListener() {
Expand All @@ -99,18 +95,18 @@ public void checkStateChanged(final CheckStateChangedEvent event) {
}
}
}
});
});
}

private void createLocationColumn(Table table) {
TableColumn column = new TableColumn(table, SWT.NULL);
column.setText("Location");
column.setText("Location");
column.setWidth(DEFAULT_COLUMN_WIDTH);
}

private void createNameColumn(Table table) {
TableColumn column = new TableColumn(table, SWT.NULL);
column.setText("Name");
column.setText("Name");
column.setWidth(DEFAULT_COLUMN_WIDTH);
}

Expand All @@ -124,15 +120,15 @@ private Table createRuntimesTable(Composite parent) {
runtimesTable.setLinesVisible(true);
return runtimesTable;
}

private Composite createPageBodyControl(Composite ancestor) {
Composite result = new Composite(ancestor, SWT.NONE);
result.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
result.setLayoutData(gd);
return result;
}

private void createLayout(Composite ancestor) {
GridLayout layout= new GridLayout();
layout.numColumns= 1;
Expand All @@ -150,14 +146,14 @@ private Label createWrapLabel(Composite parent) {
l.setLayoutData(gd);
return l;
}

private void createVerticalSpacer(Composite parent) {
Label lbl = new Label(parent, SWT.NONE);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = ((GridLayout)parent.getLayout()).numColumns;
lbl.setLayoutData(gd);
}

private void initializeForgeInstallations() {
runtimes = new ArrayList<ForgeRuntime>();
for (ForgeRuntime runtime : ForgeCorePreferences.INSTANCE.getRuntimes()) {
Expand Down Expand Up @@ -191,12 +187,12 @@ public void run() {
ForgeCorePreferences.INSTANCE.setRuntimes(runtimes, defaultRuntime);
refreshNeeded = false;
}
});
});
if(canceled[0]) {
return false;
}
}
return super.performOk();
}
}

}

0 comments on commit fdaaaf7

Please sign in to comment.