1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.operations
;
12 import org
.eclipse
.core
.resources
.IFolder
;
13 import org
.eclipse
.core
.resources
.IWorkspaceRoot
;
14 import org
.eclipse
.core
.runtime
.CoreException
;
15 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
16 import org
.eclipse
.core
.runtime
.IPath
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.jdt
.annotation
.Nullable
;
23 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
24 import org
.eclipse
.jface
.operation
.ModalContext
;
25 import org
.eclipse
.osgi
.util
.NLS
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
32 * Operation to create a new experiment.
34 * @author Bernd Hufmann
37 public class NewExperimentOperation
implements IRunnableWithProgress
{
39 private final @NonNull String fExperimentName
;
40 private final @NonNull TmfExperimentFolder fExperimentFolderRoot
;
41 private @Nullable IFolder fExperimentFolder
= null;
42 private @NonNull IStatus fStatus
= Status
.OK_STATUS
;
47 * @param experimentFolder
48 * the experiment folder root {@link TmfExperimentFolder}
49 * @param experimentName
50 * the name of the experiment
52 public NewExperimentOperation (@NonNull TmfExperimentFolder experimentFolder
, @NonNull String experimentName
) {
53 fExperimentFolderRoot
= experimentFolder
;
54 fExperimentName
= experimentName
;
58 public void run(IProgressMonitor monitor
) {
59 final IFolder experimentFolder
= createExperiment(fExperimentName
);
61 monitor
.beginTask("", 1000); //$NON-NLS-1$
62 ModalContext
.checkCanceled(monitor
);
63 experimentFolder
.create(false, true, monitor
);
66 * Experiments can be set to the default experiment type. No
67 * need to force user to select an experiment type
69 IConfigurationElement ce
= TmfTraceType
.getTraceAttributes(TmfTraceType
.DEFAULT_EXPERIMENT_TYPE
);
71 experimentFolder
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, ce
.getAttribute(TmfTraceType
.ID_ATTR
));
73 fExperimentFolder
= experimentFolder
;
74 setStatus(Status
.OK_STATUS
);
75 } catch (InterruptedException e
) {
76 setStatus(Status
.CANCEL_STATUS
);
77 } catch (InvalidRegistryObjectException
| CoreException e
) {
78 String msg
= NLS
.bind(Messages
.NewExperimentOperation_CreationError
, fExperimentName
);
79 Activator
.getDefault().logError(msg
, e
);
80 setStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, msg
, e
));
85 * @return the experimentFolder
87 public @Nullable IFolder
getExperimentFolder() {
88 return fExperimentFolder
;
91 private IFolder
createExperiment(String experimentName
) {
92 IFolder expResource
= fExperimentFolderRoot
.getResource();
93 IWorkspaceRoot workspaceRoot
= expResource
.getWorkspace().getRoot();
94 IPath folderPath
= expResource
.getFullPath().append(experimentName
);
95 IFolder folder
= workspaceRoot
.getFolder(folderPath
);
100 * Set the status for this operation
105 protected void setStatus(@NonNull IStatus status
) {
110 * Returns the status of the operation execution.
114 public @NonNull IStatus
getStatus() {