From 9194204e67b86c21407b41eca453ddbc19f70f7d Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Fri, 14 May 2021 12:41:11 +0300 Subject: [PATCH 1/2] Bug 573533 - [Passage][Operator] failed to load users base Provide migration for users 0.5.0 Signed-off-by: Alexander Fedorov --- .../users/model/migration/UsersResourceHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bundles/org.eclipse.passage.lic.users.model/src/org/eclipse/passage/lic/internal/users/model/migration/UsersResourceHandler.java b/bundles/org.eclipse.passage.lic.users.model/src/org/eclipse/passage/lic/internal/users/model/migration/UsersResourceHandler.java index 1e36770f4..20f64e17a 100644 --- a/bundles/org.eclipse.passage.lic.users.model/src/org/eclipse/passage/lic/internal/users/model/migration/UsersResourceHandler.java +++ b/bundles/org.eclipse.passage.lic.users.model/src/org/eclipse/passage/lic/internal/users/model/migration/UsersResourceHandler.java @@ -29,6 +29,7 @@ public final class UsersResourceHandler extends MigratingResourceHandler { protected void ensureMigrations() { migrate033(); migrate040(); + migrate050(); } @Override @@ -50,4 +51,10 @@ private void migrate040() { UsersPackage delegate = UsersPackage.eINSTANCE; EPackage.Registry.INSTANCE.put(nsUri, delegate); } + + private void migrate050() { + String nsUri = "http://www.eclipse.org/passage/lic/users/0.5.0"; //$NON-NLS-1$ + UsersPackage delegate = UsersPackage.eINSTANCE; + EPackage.Registry.INSTANCE.put(nsUri, delegate); + } } From 7e30c0a39795c6e810d8802eca8de9998477469e Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Fri, 14 May 2021 12:41:56 +0300 Subject: [PATCH 2/2] Bug 573533 - [Passage][Operator] failed to load users base Improve resource IO diagnostic Signed-off-by: Alexander Fedorov --- .../lic/emf/resource}/ResourceLoadFailed.java | 8 +++-- .../lic/emf/resource/ResourceSaveFailed.java | 27 +++++++++++++++ .../lic/internal/emf/i18n/EmfMessages.java | 3 ++ .../internal/emf/i18n/EmfMessages.properties | 8 +++-- .../.settings/.api_filters | 11 ------- .../META-INF/MANIFEST.MF | 2 +- .../loc/internal/emf/BaseDomainRegistry.java | 20 ++++++++--- .../i18n/WorkbenchEmfformsMessages.java | 2 ++ .../i18n/WorkbenchEmfformsMessages.properties | 1 + .../workbench/emfforms/parts/DetailsView.java | 14 ++++++-- .../renderers/ValidatedTextRenderer.java | 3 +- .../workbench/i18n/WorkbenchMessages.java | 1 + .../i18n/WorkbenchMessages.properties | 1 + .../wizards/BaseClassifierWizard.java | 3 +- .../wizards/InnerClassifierWizard.java | 28 ++++++++++++---- .../wizards/RootClassifierWizard.java | 33 +++++++++++++------ .../passage/loc/workbench/LocWokbench.java | 26 +++++---------- 17 files changed, 129 insertions(+), 62 deletions(-) rename bundles/{org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/diagnostic/code => org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource}/ResourceLoadFailed.java (85%) create mode 100644 bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceSaveFailed.java delete mode 100644 bundles/org.eclipse.passage.loc.api/.settings/.api_filters diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/diagnostic/code/ResourceLoadFailed.java b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceLoadFailed.java similarity index 85% rename from bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/diagnostic/code/ResourceLoadFailed.java rename to bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceLoadFailed.java index d7cebaf2d..7f00647c3 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/diagnostic/code/ResourceLoadFailed.java +++ b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceLoadFailed.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 ArSysOp + * Copyright (c) 2020, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -10,12 +10,14 @@ * Contributors: * ArSysOp - initial API and implementation *******************************************************************************/ -package org.eclipse.passage.loc.internal.api.diagnostic.code; +package org.eclipse.passage.lic.emf.resource; import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode; import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages; -@SuppressWarnings("restriction") +/** + * @since 2.0 + */ public final class ResourceLoadFailed extends TroubleCode { public ResourceLoadFailed() { diff --git a/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceSaveFailed.java b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceSaveFailed.java new file mode 100644 index 000000000..1d20679b0 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/resource/ResourceSaveFailed.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2021 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.lic.emf.resource; + +import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode; +import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages; + +/** + * @since 2.0 + */ +public final class ResourceSaveFailed extends TroubleCode { + + public ResourceSaveFailed() { + super(898, EmfMessages.ResourceSaveFailed_explanation); + } + +} diff --git a/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.java b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.java index d0d3be42f..f0ce1582f 100644 --- a/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.java +++ b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.java @@ -19,12 +19,15 @@ public final class EmfMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.passage.lic.internal.emf.i18n.EmfMessages"; //$NON-NLS-1$ public static String BaseDomainRegistry_e_load_failed; + + public static String BaseDomainRegistry_e_load_workspace; public static String BaseDomainRegistry_ok_load; public static String BaseDomainRegistry_ok_unload; public static String LicensingEcore_inpur_header; public static String LicensingEcore_input_entry; public static String LicensingEcore_input_invalid; public static String ResourceLoadFailed_explanation; + public static String ResourceSaveFailed_explanation; public static String XmiToEObject_failed_xmi_read; public static String XmiToEObject_unexpected_amount; diff --git a/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.properties b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.properties index 0e6de1c92..d822fb266 100644 --- a/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.properties +++ b/bundles/org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/internal/emf/i18n/EmfMessages.properties @@ -1,7 +1,5 @@ -BaseDomainRegistry_ok_load=Loaded {0} -BaseDomainRegistry_ok_unload=Unloaded {0} ############################################################################### -# Copyright (c) 2019, 2020 ArSysOp and others +# Copyright (c) 2019, 2021 ArSysOp and others # # This program and the accompanying materials are made available under the # terms of the Eclipse Public License 2.0 which is available at @@ -13,11 +11,15 @@ BaseDomainRegistry_ok_unload=Unloaded {0} # ArSysOp - initial API and implementation ############################################################################### +BaseDomainRegistry_ok_load=Loaded {0} +BaseDomainRegistry_ok_unload=Unloaded {0} BaseDomainRegistry_e_load_failed=Failed to load {0} +BaseDomainRegistry_e_load_workspace=Failed to load workspace LicensingEcore_inpur_header=%s error(s) occurred while analyzing your inputs: LicensingEcore_input_entry=%s. %s LicensingEcore_input_invalid=Input is invalid ResourceLoadFailed_explanation=EMF resource loading failed +ResourceSaveFailed_explanation=EMF resource saving failed XmiToEObject_failed_xmi_read=Reading xmi content failed XmiToEObject_unexpected_amount=Unexpected amount of contents in Floating License Access file: %d diff --git a/bundles/org.eclipse.passage.loc.api/.settings/.api_filters b/bundles/org.eclipse.passage.loc.api/.settings/.api_filters deleted file mode 100644 index 8a7d7c147..000000000 --- a/bundles/org.eclipse.passage.loc.api/.settings/.api_filters +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF index e9be3b66f..e01d2cde3 100644 --- a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.passage.loc.api Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.passage.loc.api -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java index 2a9d60aa5..344ecb5d8 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; @@ -31,11 +32,14 @@ import org.eclipse.emf.edit.domain.IEditingDomainProvider; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; import org.eclipse.osgi.util.NLS; +import org.eclipse.passage.lic.emf.resource.ResourceLoadFailed; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic; import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; +import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained; +import org.eclipse.passage.lic.internal.base.diagnostic.NoErrors; import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages; -import org.eclipse.passage.loc.internal.api.diagnostic.code.ResourceLoadFailed; @SuppressWarnings("restriction") public abstract class BaseDomainRegistry implements EditingDomainRegistry, IEditingDomainProvider { @@ -69,13 +73,20 @@ protected void loadResourceSet() { if (!Files.exists(domainPath)) { return; } - Files.readAllLines(domainPath).forEach(this::registerSource); + Files.readAllLines(domainPath).stream()// + .map(this::registerSource)// + .map(ServiceInvocationResult::diagnostic)// + .filter(new NoErrors().negate())// + .forEach(this::logDiagnostic); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Platform.getLog(getClass()).error(EmfMessages.BaseDomainRegistry_e_load_workspace, e); } } + protected void logDiagnostic(Diagnostic diagnostic) { + Platform.getLog(getClass()).error(new DiagnosticExplained(diagnostic).get()); + } + protected abstract Path getResourceSetPath() throws Exception; protected abstract DomainContentAdapter> createContentAdapter(); @@ -115,6 +126,7 @@ public ServiceInvocationResult loadSource(String source) { URI uri = createURI(source); ResourceSet set = editingDomain.getResourceSet(); Resource resource = createResource(uri); + resource.eAdapters().add(contentAdapter); set.getResources().add(resource); try { resource.load(getLoadOptions()); diff --git a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.java b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.java index 72fcb3570..33c277203 100644 --- a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.java +++ b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.java @@ -18,6 +18,8 @@ public final class WorkbenchEmfformsMessages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.passage.loc.internal.workbench.emfforms.i18n.WorkbenchEmfformsMessages"; //$NON-NLS-1$ + public static String DetailsView_e_save_title; + public static String DetailsView_label_details; public static String TextWithButtonRenderer_button_edit; public static String ConditionExpressionRenderer_condition_expression; diff --git a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.properties b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.properties index cefb7eb60..a01262c91 100644 --- a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.properties +++ b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/internal/workbench/emfforms/i18n/WorkbenchEmfformsMessages.properties @@ -11,6 +11,7 @@ # ArSysOp - initial API and implementation ############################################################################### +DetailsView_e_save_title=Error DetailsView_label_details=Details TextWithButtonRenderer_button_edit=Edit... diff --git a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/parts/DetailsView.java b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/parts/DetailsView.java index 1fd013ec8..41f22e2a0 100644 --- a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/parts/DetailsView.java +++ b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/parts/DetailsView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2020 ArSysOp + * Copyright (c) 2018, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,7 +12,9 @@ *******************************************************************************/ package org.eclipse.passage.loc.workbench.emfforms.parts; +import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import javax.annotation.PostConstruct; @@ -20,6 +22,7 @@ import javax.inject.Inject; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.di.Persist; @@ -46,6 +49,7 @@ import org.eclipse.emfforms.spi.swt.treemasterdetail.actions.MasterDetailAction; import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateElementCallback; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelection; @@ -250,13 +254,17 @@ public void save() { } Resource eResource = root.get(0).eResource(); if (eResource != null) { - IStatus status = LocWokbench.save(eResource); - if (status.isOK()) { + try { + eResource.save(new HashMap<>()); if (commandStack instanceof BasicCommandStack) { BasicCommandStack basicCommandStack = (BasicCommandStack) commandStack; basicCommandStack.saveIsDone(); part.setDirty(basicCommandStack.isSaveNeeded()); } + } catch (IOException e) { + String message = WorkbenchEmfformsMessages.DetailsView_e_save_title; + IStatus error = new Status(IStatus.ERROR, getClass(), message, e); + ErrorDialog.openError(content.getShell(), message, message, error); } } } diff --git a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/ValidatedTextRenderer.java b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/ValidatedTextRenderer.java index 8bd81ae70..27ebf396c 100644 --- a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/ValidatedTextRenderer.java +++ b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/ValidatedTextRenderer.java @@ -31,7 +31,6 @@ import org.eclipse.jface.databinding.swt.ISWTObservableValue; import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.passage.lic.jface.resource.LicensingColorResolver; -import org.eclipse.passage.loc.workbench.LocWokbench; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; @@ -106,7 +105,7 @@ protected String getTextMessage() { .getDisplayName(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel()) .getValue(); } catch (final NoLabelFoundException ex) { - Status status = new Status(IStatus.ERROR, LocWokbench.BUNDLE_SYMBOLIC_NAME, ex.getMessage(), ex); + Status status = new Status(IStatus.ERROR, getClass(), ex.getMessage(), ex); getReportService().report(new StatusReport(status)); } return TEXT_MESSAGE_DEFAULT; diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java index 336d39b7c..bca9138e1 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java @@ -47,6 +47,7 @@ public class WorkbenchMessages extends NLS { public static String RedoHandler_label_base; public static String RedoHandler_label_pattern; public static String BaseClassifierWizard_e_registry_null; + public static String InnerClassifierWizard_e_store; public static String InnerClassifierWizardPage_e_specify_container; public static String InnerClassifierWizardPage_text_select; public static String BaseClassifierWizard_message_e_cancelled; diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties index f87644caf..5cf4ece1a 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties @@ -42,6 +42,7 @@ LocWokbench_e_saving=Error saving resource RedoHandler_label_base=Redo RedoHandler_label_pattern={0} {1} BaseClassifierWizard_e_registry_null=EditingDomainRegistry must not be null +InnerClassifierWizard_e_store=Failed to store created object InnerClassifierWizardPage_e_specify_container=Please specify {0} InnerClassifierWizardPage_text_select=Select... BaseClassifierWizard_message_e_cancelled=Operation failed diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/BaseClassifierWizard.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/BaseClassifierWizard.java index 2a57b56df..1a34b851d 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/BaseClassifierWizard.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/BaseClassifierWizard.java @@ -27,6 +27,7 @@ import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.passage.lic.emf.meta.EntityMetadata; +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; import org.osgi.framework.Bundle; @@ -110,7 +111,7 @@ public boolean performFinish() { } } - protected abstract void store(); + protected abstract ServiceInvocationResult store(); protected void failed(Throwable target) { Bundle bundle = FrameworkUtil.getBundle(getClass()); diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/InnerClassifierWizard.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/InnerClassifierWizard.java index beec02b5d..5beba255c 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/InnerClassifierWizard.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/InnerClassifierWizard.java @@ -1,5 +1,7 @@ package org.eclipse.passage.loc.internal.workbench.wizards; +import java.io.IOException; +import java.util.HashMap; import java.util.NoSuchElementException; import java.util.Optional; @@ -9,10 +11,14 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.passage.lic.emf.meta.ComposableClassMetadata; import org.eclipse.passage.lic.emf.meta.EntityMetadata; +import org.eclipse.passage.lic.emf.resource.ResourceSaveFailed; import org.eclipse.passage.lic.internal.api.MandatoryService; +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; +import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; import org.eclipse.passage.loc.internal.workbench.SelectRequest; -import org.eclipse.passage.loc.workbench.LocWokbench; +import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; /** * Creates new root licensing object. Can be asked for a reference to a created @@ -62,18 +68,28 @@ protected InnerClassifierWizardPage createNewClassifierPage() { } @Override - protected void store() { - store(newClassifierPage.container(), newClassifierPage.candidate()); + protected ServiceInvocationResult store() { + return store(newClassifierPage.container(), newClassifierPage.candidate()); } - protected void store(Optional container, EObject candidate) { + // FIXME: AF: rework to remove Optional + protected ServiceInvocationResult store(Optional container, EObject candidate) { if (!container.isPresent()) { - return; + return new BaseServiceInvocationResult<>(Boolean.FALSE); } EReference reference = containerEReference(candidate.eClass()).get(); candidate.eSet(reference, container.get()); Resource resource = candidate.eResource(); - Optional.ofNullable(resource).ifPresent(LocWokbench::save); + if (resource == null) { + return new BaseServiceInvocationResult<>(Boolean.FALSE); + } + try { + resource.save(new HashMap<>()); + return new BaseServiceInvocationResult<>(Boolean.TRUE); + } catch (IOException e) { + return new BaseServiceInvocationResult<>( + new Trouble(new ResourceSaveFailed(), WorkbenchMessages.InnerClassifierWizard_e_store, e)); + } } private Optional containerEReference(EClass eClass) { diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizard.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizard.java index 4553b5c5d..c4847cbbf 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizard.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizard.java @@ -1,11 +1,19 @@ package org.eclipse.passage.loc.internal.workbench.wizards; +import java.io.IOException; +import java.util.HashMap; + import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.passage.lic.emf.meta.EntityMetadata; +import org.eclipse.passage.lic.emf.resource.ResourceSaveFailed; +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; +import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; +import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; -import org.eclipse.passage.loc.workbench.LocWokbench; +import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; /** * Creates new root licensing object. Can be asked for a reference to a created @@ -18,10 +26,10 @@ public final class RootClassifierWizard extends BaseClassifierWizardnull - * @param registry registry for an object to be created, must not be - * null + * @param metadata describes EMF metadata for an object to be created, must not + * be null + * @param registry registry for an object to be created, must not be + * null * @see BaseClassifierWizard * @see EntityMetadata * @see EditingDomainRegistry @@ -37,16 +45,21 @@ protected RootClassifierWizardPage createNewClassifierPage() { } @Override - protected void store() { - store(newClassifierPage.path(), newClassifierPage.candidate()); + protected ServiceInvocationResult store() { + return store(newClassifierPage.path(), newClassifierPage.candidate()); } - protected void store(String path, EObject candidate) { + protected ServiceInvocationResult store(String path, EObject candidate) { URI fileURI = URI.createFileURI(path); Resource resource = resourceSet().createResource(fileURI); resource.getContents().add(candidate); - LocWokbench.save(resource); - registry.registerSource(fileURI.toFileString()); + try { + resource.save(new HashMap<>()); + return registry.registerSource(fileURI.toFileString()); + } catch (IOException e) { + return new BaseServiceInvocationResult(new BaseDiagnostic( + new Trouble(new ResourceSaveFailed(), WorkbenchMessages.InnerClassifierWizard_e_store, e))); + } } } diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/workbench/LocWokbench.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/workbench/LocWokbench.java index f01ff7b4d..8b44d62ab 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/workbench/LocWokbench.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/workbench/LocWokbench.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2020 ArSysOp + * Copyright (c) 2018, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,25 +12,24 @@ *******************************************************************************/ package org.eclipse.passage.loc.workbench; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.StreamSupport; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.workbench.modeling.EPartService; -import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.domain.IEditingDomainProvider; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.base.diagnostic.NoErrors; +import org.eclipse.passage.lic.internal.jface.dialogs.licensing.DiagnosticDialog; import org.eclipse.passage.lic.jface.resource.LicensingImages; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistryAccess; @@ -49,8 +48,6 @@ */ public class LocWokbench { - public static final String BUNDLE_SYMBOLIC_NAME = "org.eclipse.passage.loc.workbench"; //$NON-NLS-1$ - public static final String COMMAND_VIEW_PERSPECTIVE = "org.eclipse.passage.loc.workbench.command.view.perspective"; //$NON-NLS-1$ public static final String COMMANDPARAMETER_VIEW_PERSPECTIVE_ID = "org.eclipse.passage.loc.workbench.commandparameter.perspective.id"; //$NON-NLS-1$ @@ -104,7 +101,10 @@ public static void loadDomainResource(IEclipseContext eclipseContext, String dom return; } switchPerspective(eclipseContext, perspectiveId); - registry.registerSource(selected); + ServiceInvocationResult source = registry.registerSource(selected); + if (!new NoErrors().test(source.diagnostic())) { + new DiagnosticDialog(shell, source.diagnostic()).open(); + } } public static void switchPerspective(IEclipseContext eclipseContext, String perspectiveId) { @@ -172,16 +172,6 @@ public static Object selectClassifier(Shell shell, String classifier, String return null; } - public static IStatus save(Resource resource) { - try { - // FIXME: define parameters - resource.save(null); - return Status.OK_STATUS; - } catch (IOException e) { - return new Status(IStatus.ERROR, BUNDLE_SYMBOLIC_NAME, WorkbenchMessages.LocWokbench_e_saving, e); - } - } - public static EditingDomain extractEditingDomain(IEclipseContext context) { EditingDomain editingDomain = context.get(EditingDomain.class); if (editingDomain != null) {