diff options
author | rescobar | 2011-09-02 19:07:17 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-09-02 19:07:17 +0000 |
commit | c6d3d410cfcb3225652504c865d6999495a55d25 (patch) | |
tree | ad2c7168bbe27f2395a773d9d74f9a410d0605ce /plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework | |
parent | 7fd396480adc65a36e6ad3ace2e1e42446f891d8 (diff) | |
download | org.eclipse.osee-c6d3d410cfcb3225652504c865d6999495a55d25.tar.gz org.eclipse.osee-c6d3d410cfcb3225652504c865d6999495a55d25.tar.xz org.eclipse.osee-c6d3d410cfcb3225652504c865d6999495a55d25.zip |
feature[ats_M1Y56]: Fix osee type sheet open with renderering
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework')
3 files changed, 81 insertions, 228 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java index 23806d17c10..53df445446e 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java @@ -35,6 +35,7 @@ import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.types.IArtifact; import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer; import org.eclipse.osee.framework.ui.skynet.render.FileSystemRenderer; +import org.eclipse.osee.framework.ui.skynet.render.FileToAttributeUpdateOperation; import org.eclipse.osee.framework.ui.skynet.render.PresentationType; import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.program.Program; @@ -64,7 +65,7 @@ public final class OseeDslRenderer extends FileSystemRenderer { public int getApplicabilityRating(PresentationType presentationType, IArtifact artifact) throws OseeCoreException { Artifact aArtifact = artifact.getFullArtifact(); if (!presentationType.matches(GENERALIZED_EDIT, PRODUCE_ATTRIBUTE) && !aArtifact.isHistorical()) { - if (aArtifact.isOfType(CoreArtifactTypes.AccessControlModel)) { + if (aArtifact.isOfType(CoreArtifactTypes.AccessControlModel, CoreArtifactTypes.OseeTypeDefinition)) { return ARTIFACT_TYPE_MATCH; } } @@ -119,15 +120,23 @@ public final class OseeDslRenderer extends FileSystemRenderer { @Override public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException { Artifact artifact = artifacts.iterator().next(); - StringBuilder builder = new StringBuilder(); - builder.append(parser.getStartTag(artifact)); - builder.append("\n"); - builder.append(artifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, "")); - builder.append("\n"); - builder.append(parser.getEndTag(artifact)); + + String data; + if (artifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) { + data = artifact.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, ""); + } else { + StringBuilder builder = new StringBuilder(); + builder.append(parser.getStartTag(artifact)); + builder.append("\n"); + builder.append(artifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, "")); + builder.append("\n"); + builder.append(parser.getEndTag(artifact)); + data = builder.toString(); + } + InputStream inputStream = null; try { - inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); + inputStream = new ByteArrayInputStream(data.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { OseeExceptions.wrapAndThrow(ex); } @@ -141,6 +150,16 @@ public final class OseeDslRenderer extends FileSystemRenderer { @Override protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) { - return new OseeDslArtifactUpdateOperation(parser, file); + IOperation op; + Artifact artifact = artifacts.iterator().next(); + if (artifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) { + OseeTypeModifier modifier = new OseeTypeModifier(); + op = + new FileToAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.UriGeneralStringData, + modifier); + } else { + op = new OseeDslArtifactUpdateOperation(parser, file); + } + return op; } } diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslTypeSheetRenderer.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslTypeSheetRenderer.java deleted file mode 100644 index 8f19a5ee849..00000000000 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslTypeSheetRenderer.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Created on Aug 16, 2011 - * - * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE - */ -package org.eclipse.osee.framework.core.dsl.ui.integration.internal; - -import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.DEFAULT_OPEN; -import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT; -import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.PRODUCE_ATTRIBUTE; -import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.SPECIALIZED_EDIT; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.emf.common.util.EList; -import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; -import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.OseeExceptions; -import org.eclipse.osee.framework.core.exception.OseeStateException; -import org.eclipse.osee.framework.core.model.Branch; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.util.HexUtil; -import org.eclipse.osee.framework.logging.OseeLevel; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; -import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; -import org.eclipse.osee.framework.skynet.core.types.IArtifact; -import org.eclipse.osee.framework.ui.skynet.render.AttributeModifier; -import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer; -import org.eclipse.osee.framework.ui.skynet.render.FileSystemRenderer; -import org.eclipse.osee.framework.ui.skynet.render.PresentationType; -import org.eclipse.osee.framework.ui.skynet.render.WholeAttributeUpdateOperation; -import org.eclipse.osee.framework.ui.swt.Displays; -import org.eclipse.swt.program.Program; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; - -public class OseeDslTypeSheetRenderer extends FileSystemRenderer { - private static final String COMMAND_ID = "org.eclipse.osee.framework.core.dsl.OseeDslTypeSheet.editor.command"; - - @Override - public String getName() { - return "OseeDsl Editor"; - } - - @Override - public DefaultArtifactRenderer newInstance() { - return new OseeDslTypeSheetRenderer(); - } - - @Override - public int getApplicabilityRating(PresentationType presentationType, IArtifact artifact) throws OseeCoreException { - Artifact aArtifact = artifact.getFullArtifact(); - if (!presentationType.matches(GENERALIZED_EDIT, PRODUCE_ATTRIBUTE) && !aArtifact.isHistorical()) { - if (aArtifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) { - return ARTIFACT_TYPE_MATCH; - } - } - return NO_MATCH; - } - - @Override - public List<String> getCommandIds(CommandGroup commandGroup) { - ArrayList<String> commandIds = new ArrayList<String>(1); - if (commandGroup.isEdit()) { - commandIds.add(COMMAND_ID); - } - return commandIds; - } - - @Override - public boolean supportsCompare() { - return true; - } - - @SuppressWarnings("unused") - @Override - public void open(final List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException { - final PresentationType resultantpresentationType = - presentationType == DEFAULT_OPEN ? SPECIALIZED_EDIT : presentationType; - - Displays.ensureInDisplayThread(new Runnable() { - @Override - public void run() { - if (!artifacts.isEmpty()) { - try { - IFile file = renderToFile(artifacts, resultantpresentationType); - if (file != null) { - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, file); - } - } catch (CoreException ex) { - OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); - } - } - } - }); - } - - @SuppressWarnings("unused") - @Override - public String getAssociatedExtension(Artifact artifact) throws OseeCoreException { - return "osee"; - } - - @Override - public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException { - // Pattern pattern = Pattern.compile("import\\s\"platform:/plugin/(.*)/support/(.+\\.osee)\""); - Artifact artifact = artifacts.iterator().next(); - StringBuilder builder = new StringBuilder(); - String sheetData = artifact.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, ""); - // Matcher m = pattern.matcher(sheetData); - // ChangeSet cs = new ChangeSet(sheetData); - // String fileName, packageName, change, importStatement; - // while (m.find()) { - // fileName = m.group(2); - // packageName = m.group(1); - // importStatement = m.group(0); - // change = ""; - // for (String line : importStatement.split("\n")) { - // change += "//" + line + "\n"; - // } - // change += "import \"" + OseeData.getPath() + "\\.working\\Common\\" + fileName + "\""; - // cs.replace(m.start(), m.end(), change); - // } - - builder.append(sheetData); - InputStream inputStream = null; - try { - inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); - } catch (UnsupportedEncodingException ex) { - OseeExceptions.wrapAndThrow(ex); - } - return inputStream; - } - - @Override - public Program getAssociatedProgram(Artifact artifact) throws OseeCoreException { - throw new OseeCoreException("should not be called"); - } - - @Override - protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) { - Modifier mod = new Modifier(); - return new WholeAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.UriGeneralStringData, mod); - } - - private class Modifier implements AttributeModifier { - - @Override - public String modifyForSave(Artifact owner, String value) throws OseeCoreException { - List<Artifact> artifacts = - ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.OseeTypeDefinition, BranchManager.getCommonBranch()); - StringBuilder combinedSheets = new StringBuilder(); - for (Artifact art : artifacts) { - String sheetData; - if (art.equals(owner)) { - sheetData = value; - } else { - sheetData = art.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, ""); - } - combinedSheets.append(sheetData.replaceAll("import\\s+\"", "// import \"")); - } - OseeDsl model = ModelUtil.loadModel("osee:/TypeModel.osee", combinedSheets.toString()); - - Set<Long> uuids = new HashSet<Long>(); - EList<XArtifactType> artifactTypes = model.getArtifactTypes(); - EList<XAttributeType> attributeTypes = model.getAttributeTypes(); - EList<XOseeEnumType> enumTypes = model.getEnumTypes(); - EList<XRelationType> relationTypes = model.getRelationTypes(); - - for (XArtifactType type : artifactTypes) { - addUuid(HexUtil.toLong(type.getUuid()), uuids); - } - for (XAttributeType type : attributeTypes) { - addUuid(HexUtil.toLong(type.getUuid()), uuids); - } - for (XOseeEnumType type : enumTypes) { - addUuid(HexUtil.toLong(type.getUuid()), uuids); - } - for (XRelationType type : relationTypes) { - addUuid(HexUtil.toLong(type.getUuid()), uuids); - } - - if (uuids.contains(0L)) { - throw new OseeStateException("Uuid of 0 is not allowed"); - } - - return value; - } - - private void addUuid(Long id, Set<Long> set) throws OseeStateException { - if (set.contains(id)) { - throw new OseeStateException("Duplicate uuid found: [0x%X]", id); - } else { - set.add(id); - } - } - } - -} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java new file mode 100644 index 00000000000..34c6bbb5628 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java @@ -0,0 +1,53 @@ +package org.eclipse.osee.framework.core.dsl.ui.integration.internal; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.core.util.HexUtil; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.eclipse.osee.framework.ui.skynet.render.AttributeModifier; + +public class OseeTypeModifier implements AttributeModifier { + + @Override + public String modifyForSave(Artifact owner, String value) throws OseeCoreException { + List<Artifact> artifacts = + ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.OseeTypeDefinition, BranchManager.getCommonBranch()); + StringBuilder combinedSheets = new StringBuilder(); + for (Artifact art : artifacts) { + String sheetData; + if (art.equals(owner)) { + sheetData = value; + } else { + sheetData = art.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, ""); + } + combinedSheets.append(sheetData.replaceAll("import\\s+\"", "// import \"")); + } + OseeDsl oseeDsl = ModelUtil.loadModel("osee:/TypeModel.osee", combinedSheets.toString()); + + Set<Long> uuids = new HashSet<Long>(); + for (EObject object : oseeDsl.eContents()) { + if (object instanceof OseeType) { + addUuid(uuids, (OseeType) object); + } + } + Conditions.checkExpressionFailOnTrue(uuids.contains(0L), "Uuid of 0L is not allowed"); + return value; + } + + private void addUuid(Set<Long> set, OseeType type) throws OseeCoreException { + Long uuid = HexUtil.toLong(type.getUuid()); + boolean wasAdded = set.add(uuid); + Conditions.checkExpressionFailOnTrue(!wasAdded, "Duplicate uuid found: [0x%X]", uuid); + } +}
\ No newline at end of file |