Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b76b4f0151ea4cf98309a8606f333804d235cdc5 (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
/*******************************************************************************
 * Copyright (c) 2011, 2015 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.tcf.filesystem.ui.internal.celleditor;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.swt.widgets.Item;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.runtime.IFSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor;

/**
 * FSCellModifier is an <code>ICellModifier</code> of the file system tree of the target explorer.
 */
public class FSCellModifier implements ICellModifier {
	// The column property used to get the name of a given file system node.
	public static final String PROPERTY_NAME = "name"; //$NON-NLS-1$

	public FSCellModifier() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
	 */
	@Override
	public boolean canModify(Object element, String property) {
		if (property.equals(PROPERTY_NAME)) {
			if (element instanceof Item) {
				element = ((Item) element).getData();
			}
			if (element instanceof IFSTreeNode) {
				IFSTreeNode node = (IFSTreeNode) element;
				if (!node.isRootDirectory()) {
					return node.isWindowsNode() && !node.isReadOnly() || !node.isWindowsNode() && node.isWritable();
				}
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
	 */
	@Override
	public Object getValue(Object element, String property) {
		if (property.equals(PROPERTY_NAME)) {
			if (element instanceof Item) {
				element = ((Item) element).getData();
			}
			if (element instanceof IFSTreeNode) {
				IFSTreeNode node = (IFSTreeNode) element;
				return node.getName();
			}
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String,
	 * java.lang.Object)
	 */
	@Override
	public void modify(Object element, String property, Object value) {
		if (property.equals(PROPERTY_NAME)) {
			if (element instanceof Item) {
				element = ((Item) element).getData();
			}
			if (element instanceof IFSTreeNode) {
				IFSTreeNode node = (IFSTreeNode) element;
				Assert.isTrue(value != null && value instanceof String);
				String newName = (String) value;
				UiExecutor.execute(node.operationRename(newName));
			}
		}
	}
}

Back to the top