Author: snjeza
Date: 2010-11-10 14:44:18 -0500 (Wed, 10 Nov 2010)
New Revision: 26429
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
Log:
JBDS-1355 Import ESB examples - JBDS complains about runtime name - even if the name is
what the error message specifies
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-11-10
19:43:53 UTC (rev 26428)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2010-11-10
19:44:18 UTC (rev 26429)
@@ -30,7 +30,8 @@
org.eclipse.equinox.p2.ui.sdk,
org.eclipse.equinox.p2.metadata,
org.jboss.tools.portlet.core,
- org.eclipse.equinox.p2.operations
+ org.eclipse.equinox.p2.operations,
+ org.eclipse.jst.server.core
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.jboss.tools.project.examples,
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2010-11-10
19:43:53 UTC (rev 26428)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2010-11-10
19:44:18 UTC (rev 26429)
@@ -11,7 +11,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.server.core.internal.JavaServerPlugin;
+import org.eclipse.jst.server.core.internal.RuntimeClasspathContainer;
+import org.eclipse.jst.server.core.internal.RuntimeClasspathProviderWrapper;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -37,6 +45,7 @@
private static final String ESB = "esb"; //$NON-NLS-1$
private static final String PORTLET = "portlet"; //$NON-NLS-1$
private static final String REQUIRED_COMPONENTS = "required-components";
//$NON-NLS-1$
+ private static final IPath ESB_SERVER_SUPPLIED_CONTAINER_PATH = new
Path("org.jboss.esb.runtime.classpath/server.supplied");
public boolean canFix(Project project, ProjectFix fix) {
if (!ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
@@ -69,6 +78,7 @@
wtpRuntime = RuntimeManager.getRuntime(runtime.getId());
facetedProject.addTargetedRuntime(wtpRuntime, monitor);
facetedProject.setPrimaryRuntime(wtpRuntime, monitor);
+ fixEsb(eclipseProject, fix, wtpRuntime);
}
}
}
@@ -80,6 +90,61 @@
return ret;
}
+ private void fixEsb(IProject eclipseProject,
+ ProjectFix fix, org.eclipse.wst.common.project.facet.core.runtime.IRuntime wtpRuntime)
throws JavaModelException {
+ String required_components = fix.getProperties().get(REQUIRED_COMPONENTS);
+ if (required_components == null) {
+ return;
+ }
+ List<String> components = tokenize(required_components);
+ if (components == null) {
+ return;
+ }
+ boolean esbRequired = false;
+ for (String component:components) {
+ if (ESB.equals(component)) {
+ esbRequired = true;
+ break;
+ }
+ }
+ if (esbRequired) {
+ IJavaProject javaProject = JavaCore.create(eclipseProject);
+ if (javaProject != null) {
+ if (!javaProject.isOpen()) {
+ javaProject.open(null);
+ }
+ IClasspathEntry[] entries = javaProject.getRawClasspath();
+ IClasspathEntry[] newEntries = new IClasspathEntry[entries.length];
+ boolean changed = false;
+ IRuntime runtime = getRuntime(wtpRuntime);
+ for (int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
+ IPath path = entry.getPath();
+ if (new Path(RuntimeClasspathContainer.SERVER_CONTAINER).isPrefixOf(path)) {
+ RuntimeClasspathProviderWrapper rcpw =
JavaServerPlugin.findRuntimeClasspathProvider(runtime.getRuntimeType());
+ IPath serverContainerPath = new Path(RuntimeClasspathContainer.SERVER_CONTAINER)
+ .append(rcpw.getId()).append(runtime.getId());
+ newEntries[i] = JavaCore.newContainerEntry(serverContainerPath);
+ changed = true;
+ } else if (ESB_SERVER_SUPPLIED_CONTAINER_PATH.isPrefixOf(path)) {
+ IPath esbContainerPath =
ESB_SERVER_SUPPLIED_CONTAINER_PATH.append(runtime.getId());
+ newEntries[i] = JavaCore.newContainerEntry(esbContainerPath);
+ changed = true;
+ } else {
+ newEntries[i] = entry;
+ }
+ } else {
+ newEntries[i] = entry;
+ }
+ }
+ if (changed) {
+ javaProject.setRawClasspath(newEntries, new NullProgressMonitor());
+ }
+ }
+ }
+ }
+
private IRuntime getBestRuntime(Project project, ProjectFix fix) {
String allowedTypes = fix.getProperties().get(
ProjectFix.ALLOWED_TYPES);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2010-11-10
19:43:53 UTC (rev 26428)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2010-11-10
19:44:18 UTC (rev 26429)
@@ -16,15 +16,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.StringTokenizer;
import java.util.TreeSet;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.commands.ToggleState;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.Geometry;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -37,7 +35,10 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -45,14 +46,13 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Monitor;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.model.AdaptableList;
import org.eclipse.ui.part.PageBook;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IRuntimeType;
-import org.eclipse.wst.server.core.ServerCore;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.dialog.FixDialog;
@@ -64,9 +64,6 @@
import org.jboss.tools.project.examples.model.ProjectExampleSite;
import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.project.examples.model.ProjectUtil;
-import org.jboss.tools.seam.core.project.facet.SeamRuntime;
-import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.osgi.framework.Bundle;
/**
* @author snjeza
@@ -74,6 +71,7 @@
*/
public class NewProjectExamplesWizardPage extends WizardPage {
+ private static final int DEFAULT_WIDTH = 600;
private IStructuredSelection selection;
private Button showQuickFixButton;
private Combo siteCombo;
@@ -88,14 +86,14 @@
setTitle( Messages.NewProjectExamplesWizardPage_Project_Example );
setDescription( Messages.NewProjectExamplesWizardPage_Import_Project_Example );
setImageDescriptor(
ProjectExamplesActivator.imageDescriptorFromPlugin(ProjectExamplesActivator.PLUGIN_ID,
"icons/new_wiz.gif")); //$NON-NLS-1$
-
}
public void createControl(Composite parent) {
+
Composite composite = new Composite(parent,SWT.NONE);
composite.setLayout(new GridLayout(1,false));
- GridData gd = new GridData(GridData.FILL_BOTH);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
composite.setLayoutData(gd);
@@ -104,11 +102,11 @@
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
siteComposite.setLayout(gridLayout);
- gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
siteComposite.setLayoutData(gd);
final Button button = new Button(siteComposite,SWT.CHECK);
- gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
gd.horizontalSpan = 2;
button.setLayoutData(gd);
button.setText(Messages.ProjectExamplesPreferencePage_Show_experimental_sites);
@@ -126,14 +124,17 @@
final ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();
- int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
+ int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP;
final FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter,true);
filteredTree.setBackground(parent.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
final TreeViewer viewer = filteredTree.getViewer();
Tree tree = viewer.getTree();
- gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.heightHint=75;
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ GC gc = new GC(parent);
+ gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+ .getFontMetrics(), 7);
+ gc.dispose();
tree.setLayoutData(gd);
tree.setFont(parent.getFont());
@@ -144,16 +145,21 @@
final SiteFilter siteFilter = new SiteFilter();
viewer.addFilter(siteFilter);
- Label descriptionLabel = new Label(composite,SWT.NULL);
+ Label descriptionLabel = new Label(composite,SWT.NONE);
descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
- final Text text = new Text(composite,SWT.BORDER | SWT.MULTI | SWT.WRAP |
SWT.READ_ONLY);
- gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
GridData.GRAB_VERTICAL);
- gd.heightHint=75;
- text.setLayoutData(gd);
+ final Text descriptionText = new Text(composite,SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gc = new GC(parent);
+ gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+ .getFontMetrics(), 4);
+ gc.dispose();
+ descriptionText.setLayoutData(gd);
Composite internal = new Composite(composite, SWT.NULL);
internal.setLayout(new GridLayout(2,false));
- gd = new GridData(GridData.FILL_BOTH);
+ gd = new GridData(GridData.FILL, GridData.FILL, true, false);
+ gd.widthHint = DEFAULT_WIDTH;
internal.setLayoutData(gd);
Label projectNameLabel = new Label(internal,SWT.NULL);
@@ -178,13 +184,13 @@
Object selected = selection.getFirstElement();
if (selected instanceof Project && selection.size() == 1) {
Project selectedProject = (Project) selected;
- text.setText(selectedProject.getDescription());
+ descriptionText.setText(selectedProject.getDescription());
projectName.setText(selectedProject.getName());
projectURL.setText(selectedProject.getUrl());
projectSize.setText(selectedProject.getSizeAsText());
} else {
//Project selectedProject=null;
- text.setText(""); //$NON-NLS-1$
+ descriptionText.setText(""); //$NON-NLS-1$
projectName.setText(""); //$NON-NLS-1$
projectURL.setText(""); //$NON-NLS-1$
projectSize.setText(""); //$NON-NLS-1$
@@ -197,19 +203,23 @@
notesPageBook = new PageBook( internal , SWT.NONE );
notesPageBook.setLayout(new GridLayout(1,false));
- gd=new GridData(GridData.FILL_HORIZONTAL);
+ gd=new GridData(GridData.FILL, GridData.FILL, true, false);
+ gc = new GC(parent);
+ gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+ .getFontMetrics(), 6);
+ gc.dispose();
gd.horizontalSpan=2;
notesPageBook.setLayoutData( gd );
noteEmptyComposite = new Composite( notesPageBook, SWT.NONE );
noteEmptyComposite.setLayout( new GridLayout(1, false));
//notesEmptyComposite.setVisible( false );
- gd=new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
noteEmptyComposite.setLayoutData(gd);
noteComposite = new Composite(notesPageBook, SWT.NONE);
noteComposite.setLayout(new GridLayout(2,false));
- gd=new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
noteComposite.setLayoutData(gd);
noteComposite.setVisible(false);
@@ -217,8 +227,7 @@
Composite messageComposite = new Composite(noteComposite, SWT.BORDER);
messageComposite.setLayout(new GridLayout(2, false));
- gd=new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
-
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
messageComposite.setLayoutData(gd);
Label noteLabel = new Label(messageComposite,SWT.NONE);
@@ -228,16 +237,20 @@
image.setBackground(noteLabel.getBackground());
noteLabel.setImage(image);
- noteText = new Text(messageComposite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
+ noteText = new Text(messageComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP |
SWT.READ_ONLY);
noteText.setText(""); //$NON-NLS-1$
- gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
GridData.GRAB_VERTICAL);
- gd.heightHint=50;
- gd.widthHint = 400;
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gc = new GC(parent);
+ gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+ .getFontMetrics(), 3);
+ gc.dispose();
noteText.setLayoutData(gd);
noteText.setText(Messages.NewProjectExamplesWizardPage_Note);
details = new Button(noteComposite, SWT.PUSH);
details.setText(Messages.NewProjectExamplesWizardPage_Details);
+ gd=new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
+ details.setLayoutData(gd);
details.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -246,10 +259,10 @@
}
});
- showQuickFixButton = new Button(internal,SWT.CHECK);
+ showQuickFixButton = new Button(composite,SWT.CHECK);
showQuickFixButton.setText(Messages.NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog);
showQuickFixButton.setSelection(true);
- gd=new GridData(GridData.FILL_HORIZONTAL);
+ gd=new GridData(SWT.BEGINNING, SWT.BOTTOM, false, false);
gd.horizontalSpan=2;
showQuickFixButton.setLayoutData(gd);
@@ -288,8 +301,93 @@
setPageComplete(false);
setControl(composite);
+
+ configureSizeAndLocation();
}
+ private void configureSizeAndLocation() {
+ Shell shell = getContainer().getShell();
+ Point size = new Point(DEFAULT_WIDTH,shell.getSize().y);
+ shell.setSize(size);
+ Point location = getInitialLocation(size, shell);
+ shell.setBounds(getConstrainedShellBounds(new Rectangle(location.x,
+ location.y, size.x, size.y)));
+ }
+
+ private Rectangle getConstrainedShellBounds(Rectangle preferredSize) {
+ Rectangle result = new Rectangle(preferredSize.x, preferredSize.y,
+ preferredSize.width, preferredSize.height);
+
+ Monitor mon = getClosestMonitor(getShell().getDisplay(), Geometry
+ .centerPoint(result));
+
+ Rectangle bounds = mon.getClientArea();
+
+ if (result.height > bounds.height) {
+ result.height = bounds.height;
+ }
+
+ if (result.width > bounds.width) {
+ result.width = bounds.width;
+ }
+
+ result.x = Math.max(bounds.x, Math.min(result.x, bounds.x
+ + bounds.width - result.width));
+ result.y = Math.max(bounds.y, Math.min(result.y, bounds.y
+ + bounds.height - result.height));
+
+ return result;
+ }
+
+ private static Monitor getClosestMonitor(Display toSearch, Point toFind) {
+ int closest = Integer.MAX_VALUE;
+
+ Monitor[] monitors = toSearch.getMonitors();
+ Monitor result = monitors[0];
+
+ for (int idx = 0; idx < monitors.length; idx++) {
+ Monitor current = monitors[idx];
+
+ Rectangle clientArea = current.getClientArea();
+
+ if (clientArea.contains(toFind)) {
+ return current;
+ }
+
+ int distance = Geometry.distanceSquared(Geometry
+ .centerPoint(clientArea), toFind);
+ if (distance < closest) {
+ closest = distance;
+ result = current;
+ }
+ }
+
+ return result;
+ }
+
+
+ private Point getInitialLocation(Point initialSize, Shell shell) {
+ Composite parent = shell.getParent();
+
+ Monitor monitor = shell.getDisplay().getPrimaryMonitor();
+ if (parent != null) {
+ monitor = parent.getMonitor();
+ }
+
+ Rectangle monitorBounds = monitor.getClientArea();
+ Point centerPoint;
+ if (parent != null) {
+ centerPoint = Geometry.centerPoint(parent.getBounds());
+ } else {
+ centerPoint = Geometry.centerPoint(monitorBounds);
+ }
+
+ return new Point(centerPoint.x - (initialSize.x / 2), Math.max(
+ monitorBounds.y, Math.min(centerPoint.y
+ - (initialSize.y * 2 / 3), monitorBounds.y
+ + monitorBounds.height - initialSize.y)));
+ }
+
private boolean canFix(Project project,ProjectFix fix) {
String type = fix.getType();
if (ProjectFix.PLUGIN_TYPE.equals(type)) {
@@ -416,6 +514,9 @@
public boolean refresh(boolean force) {
boolean canFinish = false;
+ notesPageBook.showPage(noteEmptyComposite);
+ noteComposite.setVisible(false);
+ noteEmptyComposite.setVisible(true);
Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
Object object = iterator.next();