Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4303e5ef22b7b74cbb452635ac2503d1f3c44da6 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*********************************************************************************************
 * Copyright (c) 2011 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:
 * William Chen (Wind River)	- [345384]Provide property pages for remote file system nodes
 *********************************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.ui.internal.properties;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IWindowsFileAttributes;
import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.filesystem.ui.internal.ImageConsts;
import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;

/**
 * The dialog used to display the advanced attributes of a Windows file or
 * folder.
 */
public class AdvancedAttributesDialog extends Dialog {

	// The file or folder node whose advanced attributes are to be displayed.
	FSTreeNode node;

	/**
	 * Create the advanced attributes dialog with the specified node and a
	 * parent shell.
	 *
	 * @param parentShell
	 *            The parent shell.
	 * @param node
	 *            The file or folder node to be displayed.
	 */
	public AdvancedAttributesDialog(Shell parentShell, FSTreeNode node) {
		super(parentShell);
		this.node = node;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		Composite banner = new Composite(composite, SWT.NONE);
		GridLayout layout = new GridLayout(2, false);
		banner.setLayout(layout);
		Label label = new Label(banner, SWT.NONE);
		Image bImg = getBannerImage();
		label.setImage(bImg);
		label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		label = new Label(banner, SWT.NONE);
		if (node.isFile()) {
			label.setText(Messages.AdvancedAttributesDialog_FileBanner);
		} else if (node.isDirectory()) {
			label.setText(Messages.AdvancedAttributesDialog_FolderBanner);
		}
		createArchiveAndIndexGroup(composite);
		createCompressAndEncryptGroup(composite);
		return composite;
	}

	/**
	 * Get the image in the banner area.
	 *
	 * @return The image in the banner area.
	 */
	private Image getBannerImage() {
		return UIPlugin.getImage(ImageConsts.BANNER_IMAGE);
	}

	/**
	 * Create the compress and encrypt options group.
	 *
	 * @param parent
	 *            The parent composite where they are created.
	 */
	private void createCompressAndEncryptGroup(Composite parent) {
		Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
		group.setText(Messages.AdvancedAttributesDialog_CompressEncrypt);
		group.setLayout(new GridLayout());
		group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
		createCompress(group);
		createEncrypt(group);
	}

	/**
	 * Create the archive and indexing options group.
	 *
	 * @param parent
	 *            The parent composite where they are created.
	 */
	private void createArchiveAndIndexGroup(Composite parent) {
		Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
		group.setText(Messages.AdvancedAttributesDialog_ArchiveIndex);
		group.setLayout(new GridLayout());
		group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
		createArchive(group);
		createIndexField(group);
	}

	/**
	 * Create the indexing option field.
	 *
	 * @param group
	 *            The group widget where the field is created.
	 */
	private void createIndexField(Group group) {
		String label = node.isFile() ? Messages.AdvancedAttributesDialog_IndexFile
				: (node.isDirectory() ? Messages.AdvancedAttributesDialog_IndexFolder
						: null);
		boolean on = !node.isWin32AttrOn(IWindowsFileAttributes.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
		createOptionField(group, label, IWindowsFileAttributes.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, on);
	}

	/**
	 * Create the archive option field.
	 *
	 * @param group
	 *            The group widget where the field is created.
	 */
	private void createArchive(Group group) {
		String label = node.isFile() ? Messages.AdvancedAttributesDialog_FileArchive
				: (node.isDirectory() ? Messages.AdvancedAttributesDialog_FolderArchive
						: null);
		boolean on = node.isWin32AttrOn(IWindowsFileAttributes.FILE_ATTRIBUTE_ARCHIVE);
		createOptionField(group, label, IWindowsFileAttributes.FILE_ATTRIBUTE_ARCHIVE, on);
	}

	/**
	 * Create the encrypt option field.
	 *
	 * @param group
	 *            The group widget where the field is created.
	 */
	private void createEncrypt(Group group) {
		String label = Messages.AdvancedAttributesDialog_Encrypt;
		boolean on = node.isWin32AttrOn(IWindowsFileAttributes.FILE_ATTRIBUTE_ENCRYPTED);
		createOptionField(group, label, IWindowsFileAttributes.FILE_ATTRIBUTE_ENCRYPTED, on);
	}

	/**
	 * Create the compress option field.
	 *
	 * @param group
	 *            The group widget where the field is created.
	 */
	private void createCompress(Group group) {
		String label = Messages.AdvancedAttributesDialog_Compress;
		boolean on = node.isWin32AttrOn(IWindowsFileAttributes.FILE_ATTRIBUTE_COMPRESSED);
		createOptionField(group, label, IWindowsFileAttributes.FILE_ATTRIBUTE_COMPRESSED, on);
	}

	/**
	 * Create an option field in the specified group, using the specified label,
	 * and with the specified boolean value.
	 *
	 * @param group
	 *            The group widget where the field is created.
	 * @param label
	 *            The label used by the field.
	 * @param bit
	 * 				The bit mask to be changed once the value is changed.
	 * @param on
	 *            The boolean value to be set.
	 */
	private void createOptionField(Group group, String label, final int bit, final boolean on) {
		final Button button = new Button(group, SWT.CHECK);
		button.setText(label);
		button.setSelection(on);
		// Only the owner can edit the properties
		button.setEnabled(node.isAgentOwner());
		button.addSelectionListener(new SelectionAdapter(){
			@Override
            public void widgetSelected(SelectionEvent e) {
				if (button.getSelection() != on) {
					node.setWin32Attr(bit, on);
				}
            }
		});
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
	 */
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(Messages.AdvancedAttributesDialog_ShellTitle);
	}

	/**
	 * Get the result.
	 * @return The result.
	 */
	public FSTreeNode getResult() {
	    return node;
    }
}

Back to the top