Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3019] Restore the automatic loading of the default palette in studios
Bug: #3019 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
- Loading branch information
1 parent
2c93cf3
commit 036fd3a
Showing
8 changed files
with
186 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../sirius/web/application/editingcontext/services/api/IEditingContextPersistenceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.editingcontext.services.api; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
|
||
/** | ||
* Used to indicate if some resources should be persisted or not. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public interface IEditingContextPersistenceFilter { | ||
boolean shouldPersist(Resource resource); | ||
} |
56 changes: 0 additions & 56 deletions
56
...g/eclipse/sirius/web/application/studio/services/StudioEditingContextEPackageService.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
...a/org/eclipse/sirius/web/application/studio/services/StudioEditingContextInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.studio.services; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IEditingContextProcessor; | ||
import org.eclipse.sirius.components.domain.DomainPackage; | ||
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; | ||
import org.eclipse.sirius.components.emf.services.JSONResourceFactory; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.eclipse.sirius.components.view.View; | ||
import org.eclipse.sirius.components.view.ViewPackage; | ||
import org.eclipse.sirius.components.view.deck.DeckPackage; | ||
import org.eclipse.sirius.components.view.deck.adapters.DeckColorAdapter; | ||
import org.eclipse.sirius.components.view.diagram.DiagramPackage; | ||
import org.eclipse.sirius.components.view.diagram.adapters.DiagramColorAdapter; | ||
import org.eclipse.sirius.components.view.form.FormPackage; | ||
import org.eclipse.sirius.components.view.form.adapters.FormColorAdapter; | ||
import org.eclipse.sirius.components.view.gantt.GanttPackage; | ||
import org.eclipse.sirius.web.application.studio.services.api.IStudioCapableEditingContextPredicate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to provide the studio related features for the relevant editing context. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class StudioEditingContextInitializer implements IEditingContextProcessor { | ||
|
||
private final IStudioCapableEditingContextPredicate studioCapableEditingContextPredicate; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(StudioEditingContextInitializer.class); | ||
|
||
public StudioEditingContextInitializer(IStudioCapableEditingContextPredicate studioCapableEditingContextPredicate) { | ||
this.studioCapableEditingContextPredicate = Objects.requireNonNull(studioCapableEditingContextPredicate); | ||
} | ||
|
||
@Override | ||
public void preProcess(IEditingContext editingContext) { | ||
var isStudio = this.studioCapableEditingContextPredicate.test(editingContext); | ||
if (isStudio && editingContext instanceof IEMFEditingContext emfEditingContext) { | ||
var packageRegistry = emfEditingContext.getDomain().getResourceSet().getPackageRegistry(); | ||
packageRegistry.put(DomainPackage.eNS_URI, DomainPackage.eINSTANCE); | ||
packageRegistry.put(ViewPackage.eNS_URI, ViewPackage.eINSTANCE); | ||
packageRegistry.put(DeckPackage.eNS_URI, DeckPackage.eINSTANCE); | ||
packageRegistry.put(DiagramPackage.eNS_URI, DiagramPackage.eINSTANCE); | ||
packageRegistry.put(FormPackage.eNS_URI, FormPackage.eINSTANCE); | ||
packageRegistry.put(GanttPackage.eNS_URI, GanttPackage.eINSTANCE); | ||
|
||
var resourceSet = emfEditingContext.getDomain().getResourceSet(); | ||
this.loadStudioColorPalettes(resourceSet).ifPresent(view -> { | ||
resourceSet.eAdapters().add(new DiagramColorAdapter(view)); | ||
resourceSet.eAdapters().add(new FormColorAdapter(view)); | ||
resourceSet.eAdapters().add(new DeckColorAdapter(view)); | ||
}); | ||
} | ||
} | ||
|
||
private Optional<View> loadStudioColorPalettes(ResourceSet resourceSet) { | ||
ClassPathResource classPathResource = new ClassPathResource("studioColorPalettes.json"); | ||
URI uri = URI.createURI(IEMFEditingContext.RESOURCE_SCHEME + ":///" + UUID.nameUUIDFromBytes(classPathResource.getPath().getBytes())); | ||
var resource = new JSONResourceFactory().createResource(uri); | ||
try (var inputStream = new ByteArrayInputStream(classPathResource.getContentAsByteArray())) { | ||
resourceSet.getResources().add(resource); | ||
resource.load(inputStream, null); | ||
resource.eAdapters().add(new ResourceMetadataAdapter("studioColorPalettes")); | ||
} catch (IOException exception) { | ||
this.logger.warn("An error occured while loading document studioColorPalettes.json: {}.", exception.getMessage()); | ||
resourceSet.getResources().remove(resource); | ||
} | ||
|
||
return resource.getContents() | ||
.stream() | ||
.filter(View.class::isInstance) | ||
.map(View.class::cast) | ||
.findFirst(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...eclipse/sirius/web/application/studio/services/StudioEditingContextPersistenceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.studio.services; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.components.view.util.services.ColorPaletteService; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextPersistenceFilter; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to ensure that the default palette is never persisted. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class StudioEditingContextPersistenceFilter implements IEditingContextPersistenceFilter { | ||
@Override | ||
public boolean shouldPersist(Resource resource) { | ||
return !ColorPaletteService.SIRIUS_STUDIO_COLOR_PALETTES_URI.equals(resource.getURI().toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters