Author: stefanegli
Date: Wed Aug 28 15:08:06 2013
New Revision: 1518249
URL: http://svn.apache.org/r1518249
Log:
SLING-3032 : adding a 'new' application wizard which creates a set of
application-projects based on a maven-archetype. This feature is
whitelabel-ready - see SLING-3031
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java
(with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
(with props)
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java?rev=1518249&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
Wed Aug 28 15:08:06 2013
@@ -0,0 +1,363 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards.np;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.archetype.catalog.Archetype;
+import org.apache.maven.model.Model;
+import org.apache.sling.ide.eclipse.core.MavenLaunchHelper;
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerUtil;
+
+public abstract class AbstractNewSlingApplicationWizard extends Wizard
implements INewWizard {
+ private ChooseArchetypeWizardPage chooseArchetypePage;
+ private ArchetypeParametersWizardPage archetypeParametersPage;
+ private SetupServerWizardPage setupServerWizardPage;
+
+ // branding
+ public abstract ImageDescriptor getLogo();
+ public abstract String doGetWindowTitle();
+ public abstract boolean acceptsArchetype(Archetype archetype2);
+
+ /**
+ * Constructor for AbstractNewSlingApplicationWizard.
+ */
+ public AbstractNewSlingApplicationWizard() {
+ super();
+ setWindowTitle(doGetWindowTitle());
+ setNeedsProgressMonitor(true);
+ }
+
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ public void addPages() {
+ chooseArchetypePage = new ChooseArchetypeWizardPage(this);
+ addPage(chooseArchetypePage);
+ archetypeParametersPage = new
ArchetypeParametersWizardPage(this);
+ addPage(archetypeParametersPage);
+ setupServerWizardPage = new SetupServerWizardPage(this);
+ addPage(setupServerWizardPage);
+ }
+
+ public ChooseArchetypeWizardPage getChooseArchetypePage() {
+ return chooseArchetypePage;
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in
+ * the wizard. We will create an operation and run it
+ * using wizard as execution context.
+ */
+ public boolean performFinish() {
+ try {
+ getContainer().run(false, true, new
IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws
InvocationTargetException, InterruptedException {
+ try {
+ performFinish(monitor);
+ } catch (Exception e) {
+ // TODO proper logging
+ e.printStackTrace();
+ MessageBox messageBox = new
MessageBox(Display.getDefault().getActiveShell(),
+ SWT.OK | SWT.ICON_ERROR);
+ messageBox.setText("Creating application
failed");
+ StringBuffer sb = new StringBuffer();
+ Throwable t = e;
+ while(t!=null) {
+ if (sb.length()!=0) {
+
sb.append(System.getProperty("line.separator"));
+ }
+ sb.append(t.getMessage());
+ t = t.getCause();
+ }
+ messageBox.setMessage(sb.toString());
+ messageBox.open();
+ }
+ }
+
+ });
+ return true;
+ } catch (InterruptedException e) {
+ // that's fine, the user interrupted - dont complain
+ return false;
+ } catch (InvocationTargetException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ MessageBox messageBox = new
MessageBox(Display.getDefault().getActiveShell(),
+ SWT.OK | SWT.ICON_ERROR);
+ messageBox.setText("Creating application failed");
+ StringBuffer sb = new StringBuffer();
+ Throwable t = e;
+ while(t!=null) {
+ if (sb.length()!=0) {
+ sb.append(System.getProperty("line.separator"));
+ }
+ sb.append(t.getMessage());
+ t = t.getCause();
+ }
+ messageBox.setMessage(sb.toString());
+ messageBox.open();
+ return false;
+ }
+ }
+
+ private boolean performFinish(IProgressMonitor monitor) throws
Exception {
+
+ IPath location = chooseArchetypePage.getLocation();
+ Archetype archetype =
chooseArchetypePage.getSelectedArchetype();
+ String groupId = archetypeParametersPage.getGroupId();
+ String artifactId = archetypeParametersPage.getArtifactId();
+ String version = archetypeParametersPage.getVersion();
+ String javaPackage = archetypeParametersPage.getJavaPackage();
+ Properties properties = archetypeParametersPage.getProperties();
+ ProjectImportConfiguration configuration = new
ProjectImportConfiguration();
+
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ List<IProject> projects =
MavenPlugin.getProjectConfigurationManager().createArchetypeProjects(
+ location, archetype, groupId, artifactId,
version, javaPackage, properties, configuration, monitor);
+
+ monitor.worked(3);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ List<IProject> contentProjects = new LinkedList<IProject>();
+ List<IProject> bundleProjects = new LinkedList<IProject>();
+ IProject reactorProject = null;
+ for (Iterator<IProject> it = projects.iterator();
it.hasNext();) {
+ IProject project = it.next();
+ IFile pomFile = project.getFile("pom.xml");
+ if (!pomFile.exists()) {
+ // then ignore this project - we only deal with
maven projects
+ continue;
+ }
+ final Model model =
MavenPlugin.getMavenModelManager().readMavenModel(pomFile);
+ final String packaging = model.getPackaging();
+
+ if ("content-package".equals(packaging)) {
+ contentProjects.add(project);
+ } else if ("bundle".equals(packaging)) {
+ bundleProjects.add(project);
+ } else if ("pom".equals(packaging)) {
+ if (reactorProject==null) {
+ reactorProject = project;
+ } else {
+ IPath currLocation =
project.getFullPath();
+ IPath prevLocation =
reactorProject.getFullPath();
+ if
(currLocation.isPrefixOf(prevLocation)) {
+ // assume reactor is up in the
folder structure
+ reactorProject = project;
+ }
+ }
+ }
+ }
+
+ IServer server = setupServerWizardPage.getOrCreateServer();
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ for (Iterator<IProject> it = contentProjects.iterator();
it.hasNext();) {
+ IProject aContentProject = it.next();
+ configureContentProject(aContentProject, projects,
monitor);
+ }
+ for (Iterator<IProject> it = bundleProjects.iterator();
it.hasNext();) {
+ IProject aBundleProject = it.next();
+ configureBundleProject(aBundleProject, projects,
monitor);
+ }
+
+ configureReactorProject(reactorProject, monitor);
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ finishConfiguration(projects, server, monitor);
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ updateProjectConfigurations(projects, monitor);
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ monitor.worked(2);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ // add the bundle and content projects, ie modules, to the
server
+ List<IModule> modules = new LinkedList<IModule>();
+ for (Iterator<IProject> it = bundleProjects.iterator();
it.hasNext();) {
+ IProject project = it.next();
+ IModule module = ServerUtil.getModule(project);
+ modules.add(module);
+ }
+ for (Iterator<IProject> it = contentProjects.iterator();
it.hasNext();) {
+ IProject project = it.next();
+ IModule module = ServerUtil.getModule(project);
+ modules.add(module);
+ }
+ wc.modifyModules(modules.toArray(new IModule[modules.size()]),
new IModule[0], monitor);
+ IServer newServer = wc.save(true, monitor);
+ newServer.start(ILaunchManager.RUN_MODE, monitor);
+
+ monitor.worked(2);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ ILaunchConfiguration launchConfig =
+
DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(reactorProject.getFolder(".settings").getFolder(".launches").getFile("initial_install.launch"));
+ if (launchConfig!=null) {
+ ILaunch theLaunch =
launchConfig.launch(ILaunchManager.RUN_MODE, monitor, true);
+ monitor.setTaskName("mvn install");
+ while(!theLaunch.isTerminated()) {
+ Thread.sleep(500);
+ monitor.worked(1);
+ }
+ }
+
+ wc.getOriginal().publish(IServer.PUBLISH_FULL, monitor);
+
+ // also add 'java 1.6' and 'jst.ejb 3.1'
+// IFacetedProject fp2 = ProjectFacetsManager.create(uiProject,
true, null);
+// IProjectFacet java =
ProjectFacetsManager.getProjectFacet("java");
+// fp2.installProjectFacet(java.getVersion("1.6"), null, null);
+// IProjectFacet dynamicWebModule =
ProjectFacetsManager.getProjectFacet("jst.web");
+// fp2.installProjectFacet(dynamicWebModule.getLatestVersion(),
null, null);
+
+ monitor.worked(2);
+ monitor.done();
+ return true;
+ }
+
+ protected void finishConfiguration(List<IProject> projects,
+ IServer server, IProgressMonitor monitor) throws
CoreException {
+ // nothing to be done by default - hook for subclasses
+ }
+
+ protected void updateProjectConfigurations(List<IProject> projects,
IProgressMonitor monitor) throws CoreException {
+ for (Iterator<IProject> it = projects.iterator();
it.hasNext();) {
+ IProject project = it.next();
+
MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(project,
monitor);
+ }
+ }
+
+ protected void configureBundleProject(IProject aBundleProject,
+ List<IProject> projects, IProgressMonitor monitor)
throws CoreException {
+ IProjectFacet slingContentFacet =
ProjectFacetsManager.getProjectFacet("sling.bundle");
+ IFacetedProject fp2 =
ProjectFacetsManager.create(aBundleProject, true, null);
+ fp2.installProjectFacet(slingContentFacet.getLatestVersion(),
null, null);
+ }
+
+ protected Model getMavenModel(IProject project) {
+ IFile pomFile = project.getFile("pom.xml");
+ if (!pomFile.exists()) {
+ return null;
+ }
+ try {
+ Model model =
MavenPlugin.getMavenModelManager().readMavenModel(pomFile);
+ return model;
+ } catch (CoreException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ protected void configureContentProject(IProject aContentProject,
+ List<IProject> projects, IProgressMonitor monitor)
throws CoreException {
+ IProjectFacet slingContentFacet =
ProjectFacetsManager.getProjectFacet("sling.content");
+ IFacetedProject fp2 =
ProjectFacetsManager.create(aContentProject, true, null);
+ fp2.installProjectFacet(slingContentFacet.getLatestVersion(),
null, null);
+
+
+ ProjectUtil.setSyncDirectoryPath(aContentProject,
"src/main/content/jcr_root");
+
+ // temp hack: install the launch file
+ IFolder dotLaunches =
aContentProject.getFolder(".settings").getFolder(".launches");
+ dotLaunches.create(true, true, monitor);
+ IFile launchFile =
dotLaunches.getFile("clean_package_content_package_install.launch");
+ String l =
MavenLaunchHelper.createMavenLaunchConfigMemento(aContentProject.getLocation().toOSString(),
+ "clean package content-package:install", null,
false, null);
+ InputStream in = new ByteArrayInputStream(l.getBytes());
+ launchFile.create(in, true, monitor);
+ }
+
+ protected void configureReactorProject(IProject reactorProject,
IProgressMonitor monitor) throws CoreException {
+ // temp hack: install the launch file
+ IFolder dotLaunches =
reactorProject.getFolder(".settings").getFolder(".launches");
+ dotLaunches.create(true, true, monitor);
+ IFile launchFile =
dotLaunches.getFile("initial_install.launch");
+ String l =
MavenLaunchHelper.createMavenLaunchConfigMemento(reactorProject.getLocation().toOSString(),
+ "install", null, false, null);
+ InputStream in = new ByteArrayInputStream(l.getBytes());
+ launchFile.create(in, true, monitor);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ }
+}
\ No newline at end of file
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java?rev=1518249&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java
Wed Aug 28 15:08:06 2013
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards.np;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.archetype.catalog.Archetype;
+import org.apache.maven.archetype.metadata.RequiredProperty;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+@SuppressWarnings("restriction")
+public class ArchetypeParametersWizardPage extends WizardPage {
+
+ private static final String KEY_PROPERTY = "key";
+
+ private static final String VALUE_PROPERTY = "value";
+
+ private Text groupId;
+
+ private Text artifactId;
+
+ private Text javaPackage;
+
+ private final AbstractNewSlingApplicationWizard parent;
+
+ private TableViewer propertiesViewer;
+
+ private Table propertiesTable;
+
+ private List<RequiredProperty> properties;
+
+ private Text version;
+
+ public ArchetypeParametersWizardPage(AbstractNewSlingApplicationWizard
parent) {
+ super("archetypeParametersPage");
+ this.parent = parent;
+ setTitle("Configure Archetype Properties");
+ setDescription("This step configured the archetype properties");
+ setImageDescriptor(parent.getLogo());
+ }
+
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+ layout.verticalSpacing = 9;
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText("&Group Id:");
+ groupId = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ groupId.setLayoutData(gd);
+ groupId.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ label.setText("&Artifact Id:");
+
+ artifactId = new Text(container, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ artifactId.setLayoutData(gd);
+ artifactId.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ label.setText("&Version:");
+
+ version = new Text(container, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ version.setLayoutData(gd);
+ version.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ label.setText("&Package:");
+
+ javaPackage = new Text(container, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ javaPackage.setLayoutData(gd);
+ javaPackage.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
+ label.setLayoutData(gd);
+ label.setText("&Parameters:");
+
+
+ propertiesViewer = new TableViewer(container, SWT.BORDER |
SWT.FULL_SELECTION);
+ propertiesTable = propertiesViewer.getTable();
+ propertiesTable.setLinesVisible(true);
+ propertiesTable.setHeaderVisible(true);
+ propertiesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true, 2, 2));
+
+ TableColumn propertiesTableNameColumn = new
TableColumn(propertiesTable, SWT.NONE);
+ propertiesTableNameColumn.setWidth(130);
+ propertiesTableNameColumn.setText("Name");
+
+ TableColumn propertiesTableValueColumn = new
TableColumn(propertiesTable, SWT.NONE);
+ propertiesTableValueColumn.setWidth(230);
+ propertiesTableValueColumn.setText("Value");
+
+ propertiesViewer.setColumnProperties(new String[] {KEY_PROPERTY,
VALUE_PROPERTY});
+
+ propertiesViewer.setCellEditors(new CellEditor[] {new
TextCellEditor(propertiesTable, SWT.NONE),
+ new TextCellEditor(propertiesTable, SWT.NONE)});
+ propertiesViewer.setCellModifier(new ICellModifier() {
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+ public void modify(Object element, String property, Object value)
{
+ if(element instanceof TableItem) {
+ ((TableItem) element).setText(getTextIndex(property),
String.valueOf(value));
+ dialogChanged();
+ }
+ }
+
+ public Object getValue(Object element, String property) {
+ if(element instanceof TableItem) {
+ return ((TableItem) element).getText(getTextIndex(property));
+ }
+ return null;
+ }
+ });
+
+ initialize();
+ setPageComplete(false);
+ setControl(container);
+ }
+
+ protected int getTextIndex(String property) {
+ if (KEY_PROPERTY.equals(property)) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ initialize();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initialize() {
+ if (propertiesTable==null) {
+ return;
+ }
+
+ Archetype archetype =
parent.getChooseArchetypePage().getSelectedArchetype();
+ if (archetype==null) {
+ return;
+ }
+
+ try {
+ ArchetypeManager archetypeManager =
MavenPluginActivator.getDefault().getArchetypeManager();
+ ArtifactRepository remoteArchetypeRepository =
archetypeManager.getArchetypeRepository(archetype);
+ properties = (List<RequiredProperty>)
archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository,
null);
+
+ Table table = propertiesViewer.getTable();
+ table.setItemCount(properties.size());
+ int i = 0;
+ for (Iterator<RequiredProperty> it =
properties.iterator(); it.hasNext();) {
+ RequiredProperty rp = it.next();
+ TableItem item = table.getItem(i++);
+ if (!rp.getKey().equals(item.getText())) {
+ // then create it - otherwise, reuse it
+ item.setText(0, rp.getKey());
+ item.setText(1, "");
+ item.setData(item);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Could not process
archetype: "+e.getMessage(), e);
+ }
+
+ }
+
+
+ /**
+ * Ensures that both text fields are set.
+ */
+
+ private void dialogChanged() {
+ if (groupId.getText().length()==0) {
+ updateStatus("group Id must be specified");
+ return;
+ }
+ if (artifactId.getText().length()==0) {
+ updateStatus("artifact Id must be specified");
+ return;
+ }
+ if (version.getText().length()==0) {
+ updateStatus("version must be specified");
+ return;
+ }
+ if (javaPackage.getText().length()==0) {
+ updateStatus("package must be specified");
+ return;
+ }
+ int cnt = propertiesTable.getItemCount();
+ for(int i=0; i<cnt; i++) {
+ TableItem item = propertiesTable.getItem(i);
+ if (item.getText(1).length()==0) {
+ updateStatus(item.getText(0)+" must be
specified");
+ return;
+ }
+ }
+
+ updateStatus(null);
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ public String getGroupId() {
+ return groupId.getText();
+ }
+
+ public String getArtifactId() {
+ return groupId.getText();
+ }
+
+ public String getVersion() {
+ return version.getText();
+ }
+
+ public String getJavaPackage() {
+ return javaPackage.getText();
+ }
+
+ public Properties getProperties() {
+ int cnt = propertiesTable.getItemCount();
+ Properties p = new Properties();
+ for(int i=0; i<cnt; i++) {
+ TableItem item = propertiesTable.getItem(i);
+ p.put(item.getText(0), item.getText(1));
+ }
+ return p;
+ }
+
+}
\ No newline at end of file
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java?rev=1518249&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java
Wed Aug 28 15:08:06 2013
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards.np;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.archetype.catalog.Archetype;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory;
+import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.progress.IProgressService;
+
+@SuppressWarnings("restriction")
+public class ChooseArchetypeWizardPage extends WizardPage {
+
+ private static final String LOADING_PLEASE_WAIT = "loading, please
wait...";
+ private List knownArchetypesList;
+ private Map<String, Archetype> archetypesMap = new HashMap<String,
Archetype>();
+ private Button useDefaultWorkspaceLocationButton;
+ private Label locationLabel;
+ private Combo locationCombo;
+ private final AbstractNewSlingApplicationWizard parent;
+
+ public ChooseArchetypeWizardPage(AbstractNewSlingApplicationWizard
parent) {
+ super("chooseArchetypePage");
+ this.parent = parent;
+ setTitle("Choose Project Location and Archetype");
+ setDescription("This step defines the project location and
archetype");
+ setImageDescriptor(parent.getLogo());
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
+ layout.verticalSpacing = 9;
+
+ useDefaultWorkspaceLocationButton = new Button(container,
SWT.CHECK);
+ GridData useDefaultWorkspaceLocationButtonData = new
GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
+
useDefaultWorkspaceLocationButton.setLayoutData(useDefaultWorkspaceLocationButtonData);
+ useDefaultWorkspaceLocationButton
+ .setText("Use default Workspace location");
+ useDefaultWorkspaceLocationButton.addSelectionListener(new
SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean inWorkspace =
useDefaultWorkspaceLocationButton.getSelection();
+ locationLabel.setEnabled(!inWorkspace);
+ locationCombo.setEnabled(!inWorkspace);
+ dialogChanged();
+ }
+ });
+ useDefaultWorkspaceLocationButton.setSelection(true);
+
+ locationLabel = new Label(container, SWT.NONE);
+ GridData locationLabelData = new GridData();
+ locationLabelData.horizontalIndent = 10;
+ locationLabel.setLayoutData(locationLabelData);
+ locationLabel.setText("Location:");
+ locationLabel.setEnabled(false);
+
+ locationCombo = new Combo(container, SWT.NONE);
+ GridData locationComboData = new GridData(SWT.FILL, SWT.CENTER,
true, false);
+ locationCombo.setLayoutData(locationComboData);
+ locationCombo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+ locationCombo.setEnabled(false);
+
+ Button locationBrowseButton = new Button(container, SWT.NONE);
+ GridData locationBrowseButtonData = new GridData(SWT.FILL,
SWT.CENTER, false, false);
+ locationBrowseButton.setLayoutData(locationBrowseButtonData);
+ locationBrowseButton.setText("Browse...");
+ locationBrowseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setText("Select Location");
+
+ String path = locationCombo.getText();
+ if(path.length() == 0) {
+ path =
ResourcesPlugin.getWorkspace().getRoot().getLocation().toPortableString();
+ }
+ dialog.setFilterPath(path);
+
+ String selectedDir = dialog.open();
+ if(selectedDir != null) {
+ locationCombo.setText(selectedDir);
+ useDefaultWorkspaceLocationButton.setSelection(false);
+ dialogChanged();
+ }
+ }
+ });
+
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText("&Archetype:");
+
+ knownArchetypesList = new List(container, SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ knownArchetypesList.setLayoutData(gd);
+ knownArchetypesList.addSelectionListener(new SelectionAdapter()
{
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ dialogChanged();
+ }
+ });
+
+ initialize();
+ setPageComplete(false);
+ setControl(container);
+ }
+
+ public Archetype getSelectedArchetype() {
+ String[] sel = knownArchetypesList.getSelection();
+ if (sel==null || sel.length!=1) {
+ return null;
+ }
+ String s = sel[0];
+ Archetype a = archetypesMap.get(s);
+ return a;
+ }
+
+ private void initialize() {
+ knownArchetypesList.add(LOADING_PLEASE_WAIT);
+ IWorkbench workbench =
DebugUIPlugin.getDefault().getWorkbench();
+ IProgressService progressService =
workbench.getProgressService();
+ try {
+ progressService.run(true, false, new
IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor)
throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask("discoverying
archetypes...", 5);
+ ArchetypeManager manager =
MavenPluginActivator.getDefault().getArchetypeManager();
+ monitor.worked(1);
+ Collection<ArchetypeCatalogFactory>
archetypeCatalogs = manager.getArchetypeCatalogs();
+ monitor.worked(2);
+ ArrayList<Archetype> list = new
ArrayList<Archetype>();
+ for(ArchetypeCatalogFactory catalog :
archetypeCatalogs) {
+ try {
+ @SuppressWarnings("unchecked")
+ java.util.List<Archetype>
arcs = catalog.getArchetypeCatalog().getArchetypes();
+ if(arcs != null) {
+ list.addAll(arcs);
+ }
+ } catch(Exception ce) {
+ ce.printStackTrace();
+ }
+ }
+ monitor.worked(1);
+ for (Iterator<Archetype> it = list
+ .iterator();
it.hasNext();) {
+ Archetype archetype2 =
it.next();
+ if
(parent.acceptsArchetype(archetype2)) {
+ String key =
keyFor(archetype2);
+ archetypesMap.put(key,
archetype2);
+ }
+
+ }
+ monitor.worked(1);
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ Set<String> keys =
archetypesMap.keySet();
+ knownArchetypesList.removeAll();
+ for (Iterator<String> it =
keys.iterator(); it
+
.hasNext();) {
+ String aKey =
it.next();
+
knownArchetypesList.add(aKey);
+ }
+ knownArchetypesList.pack();
+ }
+ });
+ monitor.done();
+
+ }
+ });
+ } catch (InvocationTargetException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ }
+ }
+
+ private String keyFor(Archetype archetype2) {
+ return archetype2.getGroupId() + " :
"+archetype2.getArtifactId() + " : "+archetype2.getVersion();
+ }
+
+ private void dialogChanged() {
+ if (knownArchetypesList.getItemCount()==1 &&
+
knownArchetypesList.getItem(0).equals(LOADING_PLEASE_WAIT)) {
+ setErrorMessage(null);
+ setPageComplete(false);
+ return;
+ }
+ if (knownArchetypesList.getSelectionCount()!=1) {
+ updateStatus("archetype must be selected");
+ return;
+ }
+ if (!useDefaultWorkspaceLocationButton.getSelection() &&
+ locationCombo.getText().length()==0) {
+ updateStatus("location must be specified");
+ return;
+ }
+ updateStatus(null);
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ public IPath getLocation() {
+ if (!useDefaultWorkspaceLocationButton.getSelection() &&
+ locationCombo.getText().length()>0) {
+ return new Path(locationCombo.getText());
+ } else {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java?rev=1518249&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
(added)
+++
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
Wed Aug 28 15:08:06 2013
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards.np;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerCore;
+
+public class SetupServerWizardPage extends WizardPage {
+
+ private Button useExistingServer;
+ private Combo existingServerCombo;
+ private Button setupNewServer;
+ private Text newServerName;
+ private Text newServerHostnameName;
+ private Text newServerPort;
+ private Text newServerDebugPort;
+
+ private Map<String, IServer> serversMap = new HashMap<String,
IServer>();
+
+ public SetupServerWizardPage(AbstractNewSlingApplicationWizard parent) {
+ super("chooseArchetypePage");
+ setTitle("Select or Setup Launchpad Server");
+ setDescription("This step defines which server to use with the
new Sling application.");
+ setImageDescriptor(parent.getLogo());
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
+ layout.verticalSpacing = 9;
+
+ useExistingServer = new Button(container, SWT.RADIO);
+ GridData useExistingServerButtonData = new GridData(SWT.LEFT,
SWT.CENTER, false, false, 3, 1);
+ useExistingServer.setLayoutData(useExistingServerButtonData);
+ useExistingServer.setText("Add to existing server");
+
+ Label existingServerLabel = new Label(container, SWT.NONE);
+ GridData locationLabelData = new GridData();
+ locationLabelData.horizontalIndent = 10;
+ existingServerLabel.setLayoutData(locationLabelData);
+ existingServerLabel.setText("Location:");
+ existingServerLabel.setEnabled(true);
+
+ existingServerCombo = new Combo(container, SWT.DROP_DOWN |
SWT.READ_ONLY);
+ GridData locationComboData = new GridData(SWT.FILL, SWT.CENTER,
true, false);
+ existingServerCombo.setLayoutData(locationComboData);
+ existingServerCombo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+ existingServerCombo.setEnabled(true);
+
+ {
+ setupNewServer = new Button(container, SWT.RADIO);
+ GridData setupNewServerButtonData = new GridData(SWT.LEFT,
SWT.CENTER, false, false, 3, 1);
+ setupNewServer.setLayoutData(setupNewServerButtonData);
+ setupNewServer.setText("Setup new server");
+ }
+
+ {
+ Label newServerLabel;
+ newServerLabel = new Label(container, SWT.NONE);
+ GridData newServerLabelData = new GridData();
+ newServerLabelData.horizontalIndent = 10;
+ newServerLabel.setLayoutData(newServerLabelData);
+ newServerLabel.setText("Server name:");
+ newServerLabel.setEnabled(true);
+ }
+
+ {
+ newServerName = new Text(container, SWT.BORDER);
+ GridData newServerNameData = new GridData(SWT.FILL,
SWT.FILL, true, false, 2, 1);
+ newServerName.setLayoutData(newServerNameData);
+ }
+
+ {
+ Label newServerHostnameLabel;
+ newServerHostnameLabel = new Label(container, SWT.NONE);
+ GridData newServerHostnameLabelData = new GridData();
+ newServerHostnameLabelData.horizontalIndent = 10;
+
newServerHostnameLabel.setLayoutData(newServerHostnameLabelData);
+ newServerHostnameLabel.setText("Host name:");
+ newServerHostnameLabel.setEnabled(true);
+ }
+
+ {
+ newServerHostnameName = new Text(container, SWT.BORDER);
+ GridData newServerHostnameNameData = new GridData(SWT.FILL,
SWT.FILL, true, false, 2, 1);
+
newServerHostnameName.setLayoutData(newServerHostnameNameData);
+ }
+
+ {
+ Label newServerPortLabel;
+ newServerPortLabel = new Label(container, SWT.NONE);
+ GridData newServerPortLabelData = new GridData();
+ newServerPortLabelData.horizontalIndent = 10;
+ newServerPortLabel.setLayoutData(newServerPortLabelData);
+ newServerPortLabel.setText("Port:");
+ newServerPortLabel.setEnabled(true);
+ }
+
+ {
+ newServerPort = new Text(container, SWT.BORDER);
+ GridData newServerPortData = new GridData(SWT.FILL,
SWT.FILL, true, false, 2, 1);
+ newServerPort.setLayoutData(newServerPortData);
+ }
+
+ {
+ Label newServerDebugPortLabel;
+ newServerDebugPortLabel = new Label(container,
SWT.NONE);
+ GridData newServerDebugPortLabelData = new GridData();
+ newServerDebugPortLabelData.horizontalIndent = 10;
+
newServerDebugPortLabel.setLayoutData(newServerDebugPortLabelData);
+ newServerDebugPortLabel.setText("Debug Port:");
+ newServerDebugPortLabel.setEnabled(true);
+ }
+
+ {
+ newServerDebugPort = new Text(container, SWT.BORDER);
+ GridData newServerDebugPortData = new GridData(SWT.FILL,
SWT.FILL, true, false, 2, 1);
+ newServerDebugPort.setLayoutData(newServerDebugPortData);
+ }
+
+
+ SelectionAdapter radioListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+
existingServerCombo.setEnabled(useExistingServer.getSelection());
+
newServerName.setEnabled(setupNewServer.getSelection());
+
newServerHostnameName.setEnabled(setupNewServer.getSelection());
+
newServerPort.setEnabled(setupNewServer.getSelection());
+
newServerDebugPort.setEnabled(setupNewServer.getSelection());
+ dialogChanged();
+ }
+ };
+ useExistingServer.addSelectionListener(radioListener);
+ setupNewServer.addSelectionListener(radioListener);
+ useExistingServer.setSelection(true);
+ setupNewServer.setSelection(false);
+
+ ModifyListener ml = new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ };
+ KeyListener kl = new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ dialogChanged();
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ dialogChanged();
+ }
+ };
+ newServerName.addModifyListener(ml);
+ newServerName.addKeyListener(kl);
+ newServerHostnameName.addModifyListener(ml);
+ newServerHostnameName.addKeyListener(kl);
+ newServerPort.addModifyListener(ml);
+ newServerPort.addKeyListener(kl);
+ newServerDebugPort.addModifyListener(ml);
+ newServerDebugPort.addKeyListener(kl);
+
+ initialize();
+ setPageComplete(false);
+ setControl(container);
+ }
+
+ private void initialize() {
+ IServer[] servers = ServerCore.getServers();
+ for (int i = 0; i < servers.length; i++) {
+ IServer server = servers[i];
+ String key = keyFor(server);
+ serversMap.put(key, server);
+ existingServerCombo.add(key);
+ }
+ }
+
+ private String keyFor(IServer server) {
+ return server.getName();
+ }
+
+ private void dialogChanged() {
+ if (useExistingServer.getSelection()) {
+ if (existingServerCombo.getSelectionIndex()==-1) {
+ updateStatus("Choose existing server from the
list");
+ return;
+ }
+ } else if (setupNewServer.getSelection()) {
+ if (newServerName.getText().length()==0 ||
+
newServerHostnameName.getText().length()==0 ||
+ newServerPort.getText().length()==0 ||
+
newServerDebugPort.getText().length()==0) {
+ updateStatus("Enter values for new server");
+ return;
+ }
+ }
+ updateStatus(null);
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ IServer getOrCreateServer() {
+ if (useExistingServer.getSelection()) {
+ String key =
existingServerCombo.getItem(existingServerCombo.getSelectionIndex());
+ return serversMap.get(key);
+ } else {
+ IServerType serverType =
ServerCore.findServerType("org.apache.sling.ide.launchpadServer");
+ @SuppressWarnings("unused")
+ IRuntime existingRuntime =
null;//ServerCore.findRuntime("org.apache.sling.ide.launchpadRuntimeType");
+ IRuntime[] existingRuntimes = ServerCore.getRuntimes();
+ for (int i = 0; i < existingRuntimes.length; i++) {
+ IRuntime aRuntime = existingRuntimes[i];
+ if
(aRuntime.getRuntimeType().getId().equals("org.apache.sling.ide.launchpadRuntimeType"))
{
+ existingRuntime = aRuntime;
+ }
+ }
+ IRuntimeType serverRuntime =
ServerCore.findRuntimeType("org.apache.sling.ide.launchpadRuntimeType");
+ try {
+ IRuntime runtime =
serverRuntime.createRuntime(null, new NullProgressMonitor());
+ runtime =
runtime.createWorkingCopy().save(true, new NullProgressMonitor());
+ IServerWorkingCopy wc =
serverType.createServer(null, null, runtime, new NullProgressMonitor());
+ wc.setHost(newServerHostnameName.getText());
+ wc.setName(newServerName.getText() + "
(external)");
+
wc.setAttribute(ISlingLaunchpadServer.PROP_PORT,
Integer.parseInt(newServerPort.getText()));
+
wc.setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT,
Integer.parseInt(newServerDebugPort.getText()));
+ wc.setAttribute("auto-publish-setting", 2); //
2: automatically publish when resources change
+ wc.setAttribute("auto-publish-time", 0); //
0: zero delay after a resource change (and the builder was kicked, I guess)
+ wc.setRuntime(runtime);
+ return wc.save(true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ // TODO proper logging
+ e.printStackTrace();
+ }
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain