| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2013 Ericsson |
| 3 | * |
| 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 | * |
| 9 | * Contributors: |
| 10 | * Marc-Andre Laperle - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; |
| 14 | |
| 15 | import org.eclipse.core.resources.IResource; |
| 16 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
| 17 | import org.eclipse.swt.graphics.Image; |
| 18 | |
| 19 | /** |
| 20 | * A trace package element representing a single supplementary file |
| 21 | * |
| 22 | * @author Marc-Andre Laperle |
| 23 | */ |
| 24 | public class TracePackageSupplFileElement extends TracePackageElement { |
| 25 | |
| 26 | private static final String SUPPL_FILE_ICON_PATH = "icons/obj16/thread_obj.gif"; //$NON-NLS-1$ |
| 27 | |
| 28 | private final IResource fResource; |
| 29 | private final String fSuppFileName; |
| 30 | |
| 31 | /** |
| 32 | * Constructor used when exporting |
| 33 | * |
| 34 | * @param resource |
| 35 | * the resource representing this supplementary file in the |
| 36 | * workspace |
| 37 | * @param parent |
| 38 | * the parent element |
| 39 | */ |
| 40 | public TracePackageSupplFileElement(IResource resource, TracePackageElement parent) { |
| 41 | super(parent); |
| 42 | fResource = resource; |
| 43 | fSuppFileName = null; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Constructor used when importing |
| 48 | * |
| 49 | * @param suppFileName |
| 50 | * the name to be used for the supplementary file in the |
| 51 | * workspace |
| 52 | * @param parent |
| 53 | * the parent element |
| 54 | */ |
| 55 | public TracePackageSupplFileElement(String suppFileName, TracePackageElement parent) { |
| 56 | super(parent); |
| 57 | this.fSuppFileName = suppFileName; |
| 58 | fResource = null; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get the resource corresponding to this supplementary file |
| 63 | * |
| 64 | * @return the resource corresponding to this supplementary file |
| 65 | */ |
| 66 | public IResource getResource() { |
| 67 | return fResource; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public String getText() { |
| 72 | return fResource != null ? fResource.getName() : fSuppFileName; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public long getSize(boolean checkedOnly) { |
| 77 | if (checkedOnly && !isChecked()) { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | return fResource.getLocation().toFile().length(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Image getImage() { |
| 86 | return Activator.getDefault().getImageFromImageRegistry(SUPPL_FILE_ICON_PATH); |
| 87 | } |
| 88 | |
| 89 | } |