diff options
author | rescobar | 2010-08-11 05:15:18 +0000 |
---|---|---|
committer | rescobar | 2010-08-11 05:15:18 +0000 |
commit | ec05e3b08e88ed2dfac3999f2128a3e78235dddc (patch) | |
tree | 2cc20afa9a5fa559ef7809b62f6b0d4f5542ce5d /plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee | |
parent | 07f256cbdd445af563a4b60f657846956ca556cb (diff) | |
download | org.eclipse.osee-ec05e3b08e88ed2dfac3999f2128a3e78235dddc.tar.gz org.eclipse.osee-ec05e3b08e88ed2dfac3999f2128a3e78235dddc.tar.xz org.eclipse.osee-ec05e3b08e88ed2dfac3999f2128a3e78235dddc.zip |
"Team Workflow" - YGHW1 - "Block changes to requirements unless done under an appropriate action."
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee')
2 files changed, 123 insertions, 35 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslArtifactUpdateOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslArtifactUpdateOperation.java new file mode 100644 index 00000000000..b152be3503a --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslArtifactUpdateOperation.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2010 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.internal; + +import java.io.File; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.framework.jdk.core.util.Lib; +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; + +/** + * @author Roberto E. Escobar + */ +public class OseeDslArtifactUpdateOperation extends AbstractOperation { + + private final File file; + + public OseeDslArtifactUpdateOperation(File file) { + super("OseeDsl Artifact Update", Activator.PLUGIN_ID); + this.file = file; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + String source = Lib.fileToString(file); + Pair<String, String> metaData = OseeUtil.fromOseeDslArtifactSource(source); + Conditions.checkNotNull(metaData, "artifact source", "Unable to find artifact source marker for file [%s]", + file.getAbsolutePath()); + + String branchGuid = metaData.getFirst(); + String artifactGuid = metaData.getSecond(); + Branch branch = BranchManager.getBranchByGuid(branchGuid); + Artifact artifact = ArtifactQuery.getArtifactFromId(artifactGuid, branch); + + artifact.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, source); + artifact.persist(); + } +} 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 f0699732b86..b332d958936 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 @@ -11,30 +11,55 @@ package org.eclipse.osee.framework.core.dsl.ui.integration.internal; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.resources.IFile; +import org.eclipse.osee.framework.core.dsl.integration.util.OseeUtil; 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.operation.IOperation; 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.ui.plugin.util.AWorkbench; -import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; -import org.eclipse.osee.framework.ui.skynet.artifact.editor.BaseArtifactEditorInput; 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.IArtifactUpdateOperationFactory; import org.eclipse.osee.framework.ui.skynet.render.PresentationType; import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.program.Program; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; /** * @author Roberto E. Escobar */ -public final class OseeDslRenderer extends DefaultArtifactRenderer { +public final class OseeDslRenderer extends FileSystemRenderer { - private static final String OSEE_DSL_EDITOR_ID = "org.eclipse.osee.framework.core.dsl.OseeDsl"; private static final String COMMAND_ID = "org.eclipse.osee.framework.core.dsl.OseeDsl.editor.command"; + private static final class OseeDslArtifactUpdateOperationFactory implements IArtifactUpdateOperationFactory { + + @SuppressWarnings("unused") + @Override + public IOperation createUpdateOp(File file) throws OseeCoreException { + return new OseeDslArtifactUpdateOperation(file); + } + }; + + public OseeDslRenderer() { + super(new OseeDslArtifactUpdateOperationFactory()); + } + @Override public String getName() { return "OseeDsl Editor"; @@ -70,48 +95,58 @@ public final class OseeDslRenderer extends DefaultArtifactRenderer { } @Override - public void open(final List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException { + public boolean supportsCompare() { + return true; + } + + @SuppressWarnings("unused") + @Override + public void open(final List<Artifact> artifacts, final PresentationType presentationType) throws OseeCoreException { Displays.ensureInDisplayThread(new Runnable() { @Override public void run() { - try { - for (Artifact artifact : artifacts) { - // String value = artifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, ""); - AWorkbench.getActivePage().openEditor(new XtextArtifactEditorInput(artifact), OSEE_DSL_EDITOR_ID); + if (!artifacts.isEmpty()) { + try { + IFile file = getRenderedFile(artifacts, presentationType); + if (file != null) { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); + IDE.openEditor(page, file); + } + } catch (OseeCoreException ex) { + OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); + } catch (PartInitException ex) { + OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); } - } catch (CoreException ex) { - OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); } } }); - } + @SuppressWarnings("unused") @Override - public boolean supportsCompare() { - return true; + public String getAssociatedExtension(Artifact artifact) throws OseeCoreException { + return "osee"; } - private final static class XtextArtifactEditorInput extends BaseArtifactEditorInput { - - public XtextArtifactEditorInput(Artifact artifact) { - super(artifact); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof XtextArtifactEditorInput) { - return super.equals(obj); - } - return false; - } - - @Override - public Object getAdapter(Class adapter) { - System.out.println(adapter); - return super.getAdapter(adapter); + @Override + public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException { + Artifact artifact = artifacts.iterator().next(); + StringBuilder builder = new StringBuilder(); + builder.append(OseeUtil.getOseeDslArtifactSource(artifact)); + builder.append("\n"); + builder.append(artifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, "")); + 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"); + } } |