Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2e86fecb40428270575db13dd7cb567059710aef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2011 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.ui.skynet.render;

import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;

/**
 * @author Ryan D. Brooks
 */
public class FileToAttributeUpdateOperation extends AbstractOperation {
   private final Artifact artifact;
   private final IAttributeType attributeType;
   private final File file;
   private final AttributeModifier modifier;

   public FileToAttributeUpdateOperation(File file, Artifact artifact, IAttributeType attributeType, AttributeModifier validator) {
      super("File To Artifact Update", Activator.PLUGIN_ID);
      this.artifact = artifact;
      this.attributeType = attributeType;
      this.file = file;
      this.modifier = validator;
   }

   public FileToAttributeUpdateOperation(File file, Artifact artifact, IAttributeType attributeType) {
      this(file, artifact, attributeType, null);
   }

   @Override
   protected void doWork(IProgressMonitor monitor) throws OseeCoreException, IOException {
      String data = null;
      data = Lib.fileToString(file);

      if (modifier != null) {
         data = modifier.modifyForSave(artifact, data);
      }
      artifact.setSoleAttributeFromString(attributeType, data);
      artifact.persist(getClass().getSimpleName());
   }

}

Back to the top