blob: 62ac1902aa4e9af1be33fc86ec07dee700b27ea8 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.wizard.ui.allinonedsl;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.osbp.wizard.ui.Activator;
import org.eclipse.osbp.wizard.ui.basic.BasicProjectInfo;
import org.eclipse.osbp.wizard.ui.basic.CommonProjectWizardTranslator;
import org.eclipse.osbp.wizard.ui.basic.IProjectMasterTemplate;
/**
* Wizard master templates available in this wizard implementation.
*/
public class AllInOneDSLsProjectMasterTemplate implements IProjectMasterTemplate {
/** The Constant nonDefaultTemplates. */
private static final Set<String> nonDefaultTemplates = new HashSet<String>();
/** The template. */
private final String fTemplate;
/** The Constant EMPTY_TEMPLATE. */
private final static String EMPTY_TEMPLATE = "EMPTY";
/** The Constant PIM_TEMPLATE. */
private final static String PIM_TEMPLATE = "PIM";
/** The Constant EMPTY. */
public final static AllInOneDSLsProjectMasterTemplate EMPTY = new AllInOneDSLsProjectMasterTemplate(EMPTY_TEMPLATE);
/** The Constant PIM. */
public final static AllInOneDSLsProjectMasterTemplate PIM = new AllInOneDSLsProjectMasterTemplate(PIM_TEMPLATE);
/**
* Instantiates a new all in one DSLs project master template.
*
* @param template the template
*/
private AllInOneDSLsProjectMasterTemplate(String template) {
fTemplate = template;
}
@Override
public String toString() {
return fTemplate;
}
/**
* @return all available master templates.
*/
public final static Set<AllInOneDSLsProjectMasterTemplate> values() {
Set<AllInOneDSLsProjectMasterTemplate> retcode = new TreeSet<AllInOneDSLsProjectMasterTemplate>(EMPTY);
if (nonDefaultTemplates.isEmpty()) {
getAllMasterTemplates();
}
retcode.add(EMPTY);
retcode.add(PIM);
for (String template : nonDefaultTemplates) {
retcode.add(new AllInOneDSLsProjectMasterTemplate(template));
}
return retcode;
}
/**
* @return the all master templates traversing fragments.
*/
private static void getAllMasterTemplates() {
String prefix = BasicProjectInfo.TEMPLATE_BASE_PATH+"MODEL/";
Enumeration<URL> files = Activator.getInstance().getBundle().findEntries(prefix, "*", true);
while (files != null && files.hasMoreElements()) {
URL fileURL = files.nextElement();
String filePath = fileURL.getFile().trim().replace(prefix, "");
if (!filePath.trim().isEmpty() && filePath.trim().endsWith("/") && (filePath.trim().split("/").length == 1)) {
if (filePath.equals(filePath.toUpperCase())) {
String template = filePath.split("/")[0];
if (!template.equals(EMPTY_TEMPLATE) && !template.equals(PIM_TEMPLATE)) {
nonDefaultTemplates.add(filePath.split("/")[0]);
}
}
}
}
}
@Override
public String getDescription() {
return CommonProjectWizardTranslator.instance().getDocumentation(AllInOneDSLsProjectMasterTemplate.class, toString());
}
/**
* @return true if this wizard template is a build-in template (inside the main bundle org.eclipse.osbp.wizard.ui)
*/
public boolean isBuildIn() {
if (this.equals(EMPTY)) {
return true;
}
if (this.equals(PIM)) {
return true;
}
return false;
}
/**
* @return true if this wizard template is a fragment template (outside the main bundle org.eclipse.osbp.wizard.ui)
*/
public boolean isFragment() {
return !isBuildIn();
}
/**
* @param text
* @return true if a template with the given name exists
*/
public static boolean exists(String text) {
for (AllInOneDSLsProjectMasterTemplate item : values()) {
if (text.equals(item.toString())) {
return true;
}
}
return false;
}
/**
* Find the template by text, either as item name or as item description.
* @param text searching
* @return the application project master template or EMPTY if it doesn't exist
*/
public static AllInOneDSLsProjectMasterTemplate byText(String text) {
for (AllInOneDSLsProjectMasterTemplate item : values()) {
if (text.equals(item.toString())) {
return item;
}
if (text.equals(item.getDescription())) {
return item;
}
}
return EMPTY;
}
@Override
public int compare(IProjectMasterTemplate template1, IProjectMasterTemplate template2) {
return template1.getDescription().compareTo(template2.getDescription());
}
}