blob: b4dcbc8c0d4ce0b88566df8fb4f948455cd1fb1c [file] [log] [blame]
package org.eclipse.ecf.remoteservices.internal.tooling.pde;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.IPluginReference;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.OptionTemplateSection;
import org.osgi.framework.Bundle;
public class RemoteServiceHostExample1Template extends OptionTemplateSection {
private String packageName;
public RemoteServiceHostExample1Template() {
setPageCount(1);
addOption("containerType", "service.exported.configs", "ecf.generic.server", 0);
addOption("containerId", "ECF Generic Server URL", "ecftcp://localhost:3282/server", 0);
}
public void addPages(Wizard wizard) {
WizardPage page = createPage(0, "org.eclipse.pde.doc.user.rcp_mail");
page.setTitle("Hello Remote Service Host");
page.setDescription("This template creates and exports a Hello remote service");
wizard.addPage(page);
markPagesAdded();
}
public URL getTemplateLocation() {
Bundle b = Activator.getDefault().getBundle();
String path = "/templates/"+getSectionId();
URL url = b.getEntry(path);
if (url != null)
try {
return new URL(getInstallURL(), path);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
public String getSectionId() {
return "helloRemoteServiceHostExample1"; //$NON-NLS-1$
}
protected void updateModel(IProgressMonitor monitor) {
}
public String getUsedExtensionPoint() {
return null;
}
public boolean isDependentOnParentWizard() {
return true;
}
public int getNumberOfWorkUnits() {
return super.getNumberOfWorkUnits() + 1;
}
public IPluginReference[] getDependencies(String schemaVersion) {
return new IPluginReference[0];
}
protected String getFormattedPackageName(String id) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < id.length(); i++) {
char ch = id.charAt(i);
if (buffer.length() == 0) {
if (Character.isJavaIdentifierStart(ch))
buffer.append(Character.toLowerCase(ch));
} else {
if (Character.isJavaIdentifierPart(ch) || ch == '.')
buffer.append(ch);
}
}
return buffer.toString().toLowerCase(Locale.ENGLISH);
}
protected void initializeFields(IFieldData data) {
// In a new project wizard, we don't know this yet - the
// model has not been created
String packageName = getFormattedPackageName(data.getId());
initializeOption(KEY_PACKAGE_NAME, packageName);
this.packageName = getFormattedPackageName(data.getId());
}
public void initializeFields(IPluginModelBase model) {
String id = model.getPluginBase().getId();
String packageName = getFormattedPackageName(id);
initializeOption(KEY_PACKAGE_NAME, packageName);
this.packageName = getFormattedPackageName(id);
}
public String getStringOption(String name) {
if (name.equals(KEY_PACKAGE_NAME)) {
return packageName;
}
return super.getStringOption(name);
}
@Override
public String[] getNewFiles() {
return new String[0];
}
@Override
protected URL getInstallURL() {
return Activator.getDefault().getBundle().getEntry("/");
}
@Override
protected ResourceBundle getPluginResourceBundle() {
return Platform.getResourceBundle(Activator.getDefault().getBundle());
}
}