Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d458c7411f1efc4fa3e2bdaae0333e34dac7f6c1 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/

package org.eclipse.tcf.te.runtime.services.filetransfer;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.interfaces.filetransfer.IFileTransferItem;

/**
 * FileTransferItem
 */
public class FileTransferItem extends PropertiesContainer implements IFileTransferItem {

	/**
	 * Constructor.
	 */
	public FileTransferItem() {
		setProperty(PROPERTY_ENABLED, true);
		setProperty(PROPERTY_DIRECTION, HOST_TO_TARGET);
	}

	public FileTransferItem(IPath fromHost, boolean enabled) {
		this();
		if (fromHost != null)
			setProperty(PROPERTY_HOST, fromHost.toPortableString());
		setProperty(PROPERTY_ENABLED, enabled);
	}

	public FileTransferItem(IPath fromHost, IPath toTarget) {
		this();
		if (fromHost != null)
			setProperty(PROPERTY_HOST, fromHost.toPortableString());
		if (toTarget != null)
			setProperty(PROPERTY_TARGET, toTarget.toPortableString());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IFileTransferItem#isEnabled()
	 */
	@Override
	public boolean isEnabled() {
		return getBooleanProperty(PROPERTY_ENABLED);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IFileTransferItem#getHostPath()
	 */
	@Override
	public IPath getHostPath() {
		return getStringProperty(PROPERTY_HOST) != null ? new Path(getStringProperty(PROPERTY_HOST)) : null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IFileTransferItem#getTargetPath()
	 */
	@Override
	public IPath getTargetPath() {
		return getStringProperty(PROPERTY_TARGET) != null ? new Path(getStringProperty(PROPERTY_TARGET)) : null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IFileTransferItem#getDirection()
	 */
	@Override
	public int getDirection() {
		int direction = getIntProperty(PROPERTY_DIRECTION);
		return direction == TARGET_TO_HOST ? TARGET_TO_HOST : HOST_TO_TARGET;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IFileTransferItem#getOptions()
	 */
	@Override
	public String getOptions() {
		return getStringProperty(PROPERTY_OPTIONS);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.properties.PropertiesContainer#hashCode()
	 */
	@Override
	public int hashCode() {
		int hc = getHostPath() != null ? getHostPath().hashCode() : 0;
		hc = hc << 8 + (getTargetPath() != null ? getTargetPath().hashCode() : 0);
		hc = hc << 8 + getDirection();
	    return hc;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.properties.PropertiesContainer#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		boolean equals = super.equals(obj);
		if (!equals && obj instanceof IFileTransferItem) {
			boolean hostPathEqual = getHostPath() != null ? getHostPath().equals(((IFileTransferItem)obj).getHostPath()) : ((IFileTransferItem)obj).getHostPath() == null;
			boolean targetPathEqual = getTargetPath() != null ? getTargetPath().equals(((IFileTransferItem)obj).getTargetPath()) : ((IFileTransferItem)obj).getTargetPath() == null;
			boolean directionEqual = getDirection() == ((IFileTransferItem)obj).getDirection();
			return hostPathEqual && targetPathEqual && directionEqual;
		}
		return equals;
	}
}

Back to the top