public code v1
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package flintstones.model.domain.ui.provider;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextFunction;
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
|
||||
import flintstones.model.domain.ui.service.IDomainUIService;
|
||||
/**
|
||||
* The Class DomainServiceContextFunction add the Domain Service instance to global context.
|
||||
*/
|
||||
public class DomainUIServiceContextFunction extends ContextFunction {
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core.
|
||||
* contexts.IEclipseContext, java.lang.String) */
|
||||
@Override
|
||||
public Object compute(IEclipseContext context, String contextKey) {
|
||||
IDomainUIService domainService = ContextInjectionFactory.make(DomainUIServiceProvider.class, context);
|
||||
MApplication application = context.get(MApplication.class);
|
||||
IEclipseContext applicationContext = application.getContext();
|
||||
applicationContext.set(IDomainUIService.class, domainService);
|
||||
return domainService;
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package flintstones.model.domain.ui.provider;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.ui.DomainUI;
|
||||
import flintstones.entity.domain.ui.chart.DomainChart;
|
||||
import flintstones.entity.domain.ui.dialog.DomainDialog;
|
||||
import flintstones.helper.extensionpoint.BaseRegistry;
|
||||
import flintstones.helper.extensionpoint.ExtensionRegistry;
|
||||
import flintstones.model.domain.ui.service.IDomainUIService;
|
||||
|
||||
/**
|
||||
* The Class DomainUIServiceProvider.
|
||||
*
|
||||
* @author Sinbad 2
|
||||
* Service provided for Domain UI ( create domain, modify domain and domain chart )
|
||||
*/
|
||||
class DomainUIServiceProvider implements IDomainUIService {
|
||||
|
||||
/** The chart extension point. */
|
||||
private final String CHART_EXTENSION_POINT = "flintstones.domain.ui.chart.extensionpoint"; //$NON-NLS-1$
|
||||
|
||||
/** The new domain dialog extension point. */
|
||||
private final String NEW_DOMAIN_DIALOG_EXTENSION_POINT = "flintstones.domain.ui.new.dialog.extensionpoint"; //$NON-NLS-1$
|
||||
|
||||
/** The modify domain dialog extension point. */
|
||||
private final String MODIFY_DOMAIN_DIALOG_EXTENSION_POINT = "flintstones.domain.ui.modify.dialog.extensionpoint"; //$NON-NLS-1$
|
||||
|
||||
/** The chart registry. */
|
||||
private final BaseRegistry chartReg;
|
||||
|
||||
/** The new domain dialog registry. */
|
||||
private final BaseRegistry newReg;
|
||||
|
||||
/** The modify domain dialog registry. */
|
||||
private final BaseRegistry modReg;
|
||||
|
||||
/** The context. */
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
private enum registries {
|
||||
newdialog, modifydialog, chart
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiates a new domain UI service provider.
|
||||
*/
|
||||
public DomainUIServiceProvider() {
|
||||
this.chartReg = new BaseRegistry(this.CHART_EXTENSION_POINT);
|
||||
this.chartReg.setLabel_implementation(DomainUI.Fields.chart);
|
||||
this.newReg = new BaseRegistry(this.NEW_DOMAIN_DIALOG_EXTENSION_POINT);
|
||||
this.modReg = new BaseRegistry(this.MODIFY_DOMAIN_DIALOG_EXTENSION_POINT);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.domain.ui.service.IDomainUIService#getDescriptionNewDomainDialog(
|
||||
* java.lang.String) */
|
||||
@Override
|
||||
public String getDescriptionNewDomainDialog(String id) {
|
||||
ExtensionRegistry registry = this.newReg.getFirstRegistryWhere(DomainUI.Fields.uid, id);
|
||||
return registry.getAttribute(DomainUI.Fields.description);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.domain.ui.service.IDomainUIService#newDomainDialog(flintstones.
|
||||
* domain.Domain, java.lang.String) */
|
||||
@Override
|
||||
public DomainDialog newDomainDialog(Domain domain, String id) {
|
||||
DomainDialog result = (DomainDialog) this.newReg.instantiate(id, this.context);
|
||||
result.setDomainTop(domain);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.domain.ui.service.IDomainUIService#modifyDomainDialog(flintstones
|
||||
* .domain.Domain, java.lang.String) */
|
||||
@Override
|
||||
public DomainDialog modifyDomainDialog(Domain domain) {
|
||||
|
||||
|
||||
String dialogId = getModifyDomainDialogId(domain.getType());
|
||||
ExtensionRegistry er = modReg.getFirstRegistryWhere(DomainUI.Fields.uid,dialogId);
|
||||
if(er == null)
|
||||
return null;
|
||||
|
||||
DomainDialog result = (DomainDialog) this.modReg.instantiate(dialogId, this.context);
|
||||
result.setDomainTop(domain);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.domain.ui.service.IDomainUIService#getExtensionIdsForDomain(java.
|
||||
* lang.String) */
|
||||
@Override
|
||||
public String[] getExtensionIdsForDomain(String domain, String part) {
|
||||
BaseRegistry reg = getBaseRegistry(part);
|
||||
return reg.getAllAttributesWhere(DomainUI.Fields.domain, domain, DomainUI.Fields.uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the requested base registry.
|
||||
*
|
||||
* @param part the part "chart","modify","new"
|
||||
* @return the base registry
|
||||
*/
|
||||
private BaseRegistry getBaseRegistry(String part) {
|
||||
|
||||
// Compat. fix
|
||||
if (part.equals("new")) //$NON-NLS-1$
|
||||
part = "newdialog"; //$NON-NLS-1$
|
||||
else if (part.equals("modify")) //$NON-NLS-1$
|
||||
part = "modifydialog"; //$NON-NLS-1$
|
||||
|
||||
if (part.equals(registries.chart.toString()))
|
||||
return this.chartReg;
|
||||
else if (part.equals(registries.newdialog.toString()))
|
||||
return this.newReg;
|
||||
else if (part.equals(registries.modifydialog.toString()))
|
||||
return this.modReg;
|
||||
else
|
||||
throw new InvalidParameterException("Part no valida " + part); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String getExtensionNameForDomain(String domain, String part) {
|
||||
BaseRegistry reg = this.getBaseRegistry(part);
|
||||
ExtensionRegistry e = reg.getFirstRegistryWhere(DomainUI.Fields.domain, domain);
|
||||
|
||||
if(e == null)
|
||||
return null;
|
||||
|
||||
return e.getAttribute(DomainUI.Fields.uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainChart createChart(String domainId) {
|
||||
String chartId = getExtensionNameForDomain(domainId, "chart");
|
||||
|
||||
// Support for chart-less domains
|
||||
ExtensionRegistry reg = chartReg.getFirstRegistryWhere(DomainUI.Fields.uid, chartId);
|
||||
if(reg == null)
|
||||
return null;
|
||||
|
||||
if( reg.getAttribute("chart") == null )
|
||||
return null;
|
||||
|
||||
DomainChart result = (DomainChart) chartReg.instantiate(chartId, this.context);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModifyDomainDialogId(String domainType) {
|
||||
String[] dialogIds = getExtensionIdsForDomain(domainType,"modify");
|
||||
String dialogId = dialogIds[0];
|
||||
return dialogId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user