Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

548115 - [Passage] provide ability to create product version from issue license wizard : part 2 #184

Merged
merged 8 commits into from
Apr 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.passage.lic.emf.meta.ComposableClassMetadata;
import org.eclipse.passage.lic.features.FeatureDescriptor;
import org.eclipse.passage.lic.features.FeatureSetDescriptor;
import org.eclipse.passage.lic.features.FeatureVersionDescriptor;
Expand All @@ -42,8 +44,13 @@
import org.eclipse.passage.lic.users.UserOriginDescriptor;
import org.eclipse.passage.lic.users.registry.UserRegistry;
import org.eclipse.passage.lic.users.registry.UserRegistryEvents;
import org.eclipse.passage.moveto.lic.internal.features.model.FeaturesClassMetadata;
import org.eclipse.passage.moveto.lic.internal.licenses.model.LicensesClassMetadata;
import org.eclipse.passage.moveto.lic.internal.products.model.ProductsClassMetadata;
import org.eclipse.passage.moveto.lic.internal.users.model.UsersClassMetadata;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.FrameworkUtil;

public class DashboardPanelPart {

Expand Down Expand Up @@ -78,6 +85,14 @@ public void postConstruct(Composite parent, IEclipseContext context) {
createUserInfo(area);
createLicenseInfo(area);
createFooterInfo(area);
// FIXME: replace this with OSGi component registration
ComposableClassMetadata metadata = EclipseContextFactory
.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext())
.get(ComposableClassMetadata.class);
metadata.consider(new FeaturesClassMetadata());
metadata.consider(new ProductsClassMetadata());
metadata.consider(new UsersClassMetadata());
metadata.consider(new LicensesClassMetadata());
}

protected void createHeaderInfo(Composite parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.dialogs.MessageDialog;
Expand All @@ -27,7 +26,6 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lic.api.LicensingResult;
import org.eclipse.passage.lic.api.access.LicensingRequest;
import org.eclipse.passage.lic.emf.meta.ComposableClassMetadata;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.products.ProductVersionDescriptor;
Expand All @@ -38,11 +36,8 @@
import org.eclipse.passage.loc.internal.dashboard.ui.i18n.IssueLicensePageMessages;
import org.eclipse.passage.loc.users.ui.UsersUi;
import org.eclipse.passage.loc.workbench.LocWokbench;
import org.eclipse.passage.moveto.lic.internal.products.model.ProductsClassMetadata;
import org.eclipse.passage.moveto.lic.internal.users.model.UsersClassMetadata;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.osgi.framework.FrameworkUtil;

public class IssueLicenseWizard extends Wizard {

Expand All @@ -65,12 +60,6 @@ public void init(LicensePlanDescriptor plan, UserDescriptor user, ProductVersion
this.licensePlanDescriptor = plan;
this.userDescriptor = user;
this.productVersionDescriptor = version;
// FIXME: replace this with OSGi component registration
ComposableClassMetadata metadata = EclipseContextFactory
.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext())
.get(ComposableClassMetadata.class);
metadata.consider(new UsersClassMetadata());
metadata.consider(new ProductsClassMetadata());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.moveto.lic.internal.features.model;

import java.beans.FeatureDescriptor;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.eclipse.passage.lic.emf.meta.ClassMetadata;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.emf.meta.PlainEntityMetadata;
import org.eclipse.passage.lic.features.FeatureSetDescriptor;
import org.eclipse.passage.lic.features.model.meta.FeaturesPackage;

//FIXME: AF: remove restriction after moving to the right bundle
@SuppressWarnings("restriction")
public final class FeaturesClassMetadata implements ClassMetadata {

private final FeaturesPackage meta;
private final Map<Class<?>, EntityMetadata> map;

public FeaturesClassMetadata() {
meta = FeaturesPackage.eINSTANCE;
map = new HashMap<Class<?>, EntityMetadata>();
map.put(FeatureSetDescriptor.class, //
new PlainEntityMetadata(//
meta.getFeatureSet(), //
meta.getFeatureSet_Identifier(), //
meta.getFeatureSet_Name()));
map.put(FeatureDescriptor.class, //
new PlainEntityMetadata(//
meta.getFeature(), //
meta.getFeature_Identifier(), //
meta.getFeature_Name()));
}
eparovyshnaya marked this conversation as resolved.
Show resolved Hide resolved

@Override
public Optional<EntityMetadata> find(Class<?> clazz) {
return Optional.ofNullable(map.get(clazz));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.moveto.lic.internal.licenses.model;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.eclipse.passage.lic.emf.meta.ClassMetadata;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.emf.meta.PlainEntityMetadata;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;

//FIXME: AF: remove restriction after moving to the right bundle
@SuppressWarnings("restriction")
public final class LicensesClassMetadata implements ClassMetadata {

private final LicensesPackage meta;
private final Map<Class<?>, EntityMetadata> map;

public LicensesClassMetadata() {
meta = LicensesPackage.eINSTANCE;
map = new HashMap<Class<?>, EntityMetadata>();
map.put(LicensePlanDescriptor.class, //
new PlainEntityMetadata(//
meta.getLicensePlan(), //
meta.getLicensePlan_Identifier(), //
meta.getLicensePlan_Name()));
}

@Override
public Optional<EntityMetadata> find(Class<?> clazz) {
return Optional.ofNullable(map.get(clazz));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0",
Require-Bundle: org.eclipse.e4.core.services;bundle-version="0.0.0",
org.eclipse.osgi;bundle-version="0.0.0",
org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.e4.core.services;bundle-version="0.0.0",
org.eclipse.passage.lic.equinox;bundle-version="0.0.0",
org.eclipse.passage.lic.emf;bundle-version="0.0.0",
org.eclipse.passage.lic.equinox;bundle-version="0.0.0",
org.eclipse.passage.lic.products.edit;bundle-version="0.5.100",
org.eclipse.passage.lic.products.model;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.loc.api;bundle-version="0.0.0"
Service-Component: OSGI-INF/*.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lic.emf.ecore.EditingDomainRegistry;
import org.eclipse.passage.lic.emf.edit.ClassifierInitializer;
import org.eclipse.passage.lic.emf.edit.EditingDomainRegistryAccess;
Expand Down Expand Up @@ -76,20 +79,26 @@ public Optional<C> get() {
protected Optional<EObject> showWizard(Class<C> type, ClassifierInitializer initializer,
EditingDomainRegistry<?> registry) {
EntityMetadata metadata = context.get(ComposableClassMetadata.class).find(type).get();
EClass eClass = metadata.eClass();
ResourceLocator resourceLocator = new LocateResources(eClass).get();
String typeName = resourceLocator.getString(NLS.bind("_UI_{0}_type", eClass.getName())); //$NON-NLS-1$
BaseClassifierWizard<?> wizard = createWizard(type, metadata, initializer, registry);
WizardDialog dialog = new WizardDialog(context.get(Shell.class), wizard);
Shell parentShell = context.get(Shell.class);
WizardDialog dialog = new WizardDialog(parentShell, wizard);
dialog.create();
dialog.setTitle(initializer.newObjectTitle());
dialog.setMessage(initializer.newFileMessage());
dialog.setTitle(typeName);
dialog.setMessage(dialogMessage(typeName));
Shell createdShell = dialog.getShell();
Point location = createdShell.getLocation();
createdShell.setLocation(location.x + 40, location.y + 40);
createdShell.setText(initializer.newObjectMessage());
createdShell.setImage(LicensingImages.getImage(metadata.eClass().getName()));
createdShell.setText(NLS.bind(WorkbenchMessages.CreateClassifier_text_new_type, typeName));
createdShell.setImage(LicensingImages.getImage(eClass.getName()));
dialog.open();
return wizard.created();
}

protected abstract String dialogMessage(String typeName);

protected abstract BaseClassifierWizard<?> createWizard(Class<C> type, EntityMetadata metadata,
ClassifierInitializer initializer, EditingDomainRegistry<?> registry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import java.util.Optional;

import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lic.emf.ecore.EditingDomainRegistry;
import org.eclipse.passage.lic.emf.edit.ClassifierInitializer;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.internal.api.MandatoryService;
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages;
import org.eclipse.passage.loc.internal.workbench.wizards.BaseClassifierWizard;
import org.eclipse.passage.loc.internal.workbench.wizards.InnerClassifierWizard;
import org.eclipse.passage.loc.internal.workbench.wizards.RootClassifierWizard;
Expand Down Expand Up @@ -56,4 +58,9 @@ protected BaseClassifierWizard<?> createWizard(Class<I> clazz, EntityMetadata me
return new InnerClassifierWizard<I, R>(clazz, metadata, initializer, registry, request, context);
}

@Override
protected String dialogMessage(String typeName) {
return NLS.bind(WorkbenchMessages.CreateInner_message_new_type, typeName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import java.util.Optional;

import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lic.emf.ecore.EditingDomainRegistry;
import org.eclipse.passage.lic.emf.edit.ClassifierInitializer;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.internal.api.MandatoryService;
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages;
import org.eclipse.passage.loc.internal.workbench.wizards.BaseClassifierWizard;
import org.eclipse.passage.loc.internal.workbench.wizards.RootClassifierWizard;

Expand Down Expand Up @@ -51,4 +53,9 @@ protected BaseClassifierWizard<?> createWizard(Class<R> clazz, EntityMetadata me
return new RootClassifierWizard(metadata, initializer, registry);
}

@Override
protected String dialogMessage(String typeName) {
return NLS.bind(WorkbenchMessages.CreateRoot_message_new_type, typeName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.internal.workbench;

import java.util.function.Supplier;

import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.osgi.util.NLS;

/**
*
* Retrieves localized name for a given {@link EClass}
*
*/
public class EClassName implements Supplier<String> {

private final EClass eClass;

public EClassName(EClass eClass) {
this.eClass = eClass;
}

@Override
public String get() {
ResourceLocator resourceLocator = new LocateResources(eClass).get();
return resourceLocator.getString(NLS.bind("_UI_{0}_type", eClass.getName())); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.internal.workbench;

import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.EMFEditPlugin;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IItemLabelProvider;

/**
*
* Supplies EMF {@link ResourceLocator} for a given {@link EObject} or
* {@link EClass}
*
*/
public class LocateResources implements Supplier<ResourceLocator> {

private final EObject eObject;

public LocateResources(EObject eObject) {
this.eObject = eObject;
}

public LocateResources(EClass eClass) {
this.eObject = eClass.getEPackage().getEFactoryInstance().create(eClass);
}

@Override
public ResourceLocator get() {
return Optional.ofNullable(//
new ComposedAdapterFactory(//
ComposedAdapterFactory.Descriptor.Registry.INSTANCE)//
.adapt(eObject, IItemLabelProvider.class))
.filter(ResourceLocator.class::isInstance)//
.map(ResourceLocator.class::cast)//
.orElse(EMFEditPlugin.INSTANCE);
}

}
Loading