tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfExperimentElement.java
index f57192a6667b4de8db49eaa6e5419f11d3f7d4c0..73e1a7ba50cfacf7c01b4b5b40b73b7cba395693 100644 (file)
@@ -1,22 +1,29 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Ericsson
- * 
+ * Copyright (c) 2010, 2013 Ericsson
+ *
  * 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:
  *   Francois Chouinard - Initial API and implementation
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertySource2;
 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
@@ -26,9 +33,9 @@ import org.eclipse.ui.views.properties.TextPropertyDescriptor;
  * <p>
  * @version 1.0
  * @author Francois Chouinard
- * 
+ *
  */
-public class TmfExperimentElement extends TmfProjectModelElement implements IPropertySource2 {
+public class TmfExperimentElement extends TmfWithFolderElement implements IPropertySource2 {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -39,6 +46,7 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
     private static final String sfName = "name"; //$NON-NLS-1$
     private static final String sfPath = "path"; //$NON-NLS-1$
     private static final String sfLocation = "location"; //$NON-NLS-1$
+    private static final String sfFolderSuffix = "_exp"; //$NON-NLS-1$
 
     private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName);
     private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath);
@@ -54,11 +62,13 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
         sfLocationDescriptor.setCategory(sfInfoCategory);
     }
 
+    private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
     /**
-     * Constructor 
+     * Constructor
      * @param name The name of the experiment
      * @param folder The folder reference
      * @param parent The experiment folder reference.
@@ -108,6 +118,41 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
         return traces;
     }
 
+    /**
+     * Returns the file resource used to store bookmarks after creating it if necessary.
+     * The file will be created if it does not exist.
+     * @return the bookmarks file
+     * @throws CoreException if the bookmarks file cannot be created
+     * @since 2.0
+     */
+    public IFile createBookmarksFile() throws CoreException {
+        IFile file = getBookmarksFile();
+        if (!file.exists()) {
+            final IFile bookmarksFile = getProject().getExperimentsFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
+            if (!bookmarksFile.exists()) {
+                final InputStream source = new ByteArrayInputStream(new byte[0]);
+                bookmarksFile.create(source, true, null);
+            }
+            bookmarksFile.setHidden(true);
+            file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
+            file.setHidden(true);
+            file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfExperiment.class.getCanonicalName());
+        }
+        return file;
+    }
+
+    /**
+     * Returns the file resource used to store bookmarks.
+     * The file may not exist.
+     * @return the bookmarks file
+     * @since 2.0
+     */
+    public IFile getBookmarksFile() {
+        final IFolder folder = (IFolder) fResource;
+        IFile file = folder.getFile(getName() + '_');
+        return file;
+    }
+
     // ------------------------------------------------------------------------
     // IPropertySource2
     // ------------------------------------------------------------------------
@@ -127,7 +172,7 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
      */
     @Override
     public IPropertyDescriptor[] getPropertyDescriptors() {
-        return (sfDescriptors != null) ? Arrays.copyOf(sfDescriptors, sfDescriptors.length) : null;
+        return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
     }
 
     /*
@@ -137,18 +182,21 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
     @Override
     public Object getPropertyValue(Object id) {
 
-        if (sfName.equals(id))
+        if (sfName.equals(id)) {
             return getName();
+        }
 
-        if (sfPath.equals(id))
+        if (sfPath.equals(id)) {
             return getPath().toString();
+        }
 
-        if (sfLocation.equals(id))
+        if (sfLocation.equals(id)) {
             return getLocation().toString();
+        }
 
         return null;
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
@@ -183,4 +231,13 @@ public class TmfExperimentElement extends TmfProjectModelElement implements IPro
         return false;
     }
 
+    /**
+     * Return the suffix for resource names
+     * @return The folder suffix
+     */
+    @Override
+    public String getSuffix() {
+        return sfFolderSuffix;
+    }
+
 }
This page took 0.025313 seconds and 5 git commands to generate.