Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 48580c487784e0e8af772c3aa5ff67b3882551a5 (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
/*******************************************************************************
 * 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.ui.internal.wizards;

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
import org.eclipse.tcf.te.ui.controls.validator.Validator;

/**
 * The validator to validate the path of the parent directory in the new file/folder wizard
 * page is valid. It is only when it is not empty and it exists in the target peer.
 * 
 * @see Validator
 */
public class FolderValidator extends Validator {
	// The wizard page to create the new node.
	private NewNodeWizardPage page;
	
	/**
	 * Create a folder validator of the specified wizard page.
	 * 
	 * @param page The wizard page to create the new file/folder.
	 */
	public FolderValidator(NewNodeWizardPage page) {
	    super(ATTR_MANDATORY);
	    this.page = page;
    }

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.controls.validator.Validator#isValid(java.lang.String)
	 */
	@Override
	public boolean isValid(String newText) {
		if (newText == null || newText.trim().length() == 0) {
			setMessage(Messages.FolderValidator_SpecifyFolder, IMessageProvider.ERROR);
			return false;
		}
		FSTreeNode folder = page.getInputDir();
		if (folder == null) {
			setMessage(NLS.bind(Messages.FolderValidator_DirNotExist, newText), IMessageProvider.ERROR);
			return false;
		}
		if (!folder.isWritable()) {
			setMessage(NLS.bind(Messages.FolderValidator_NotWritable, newText), IMessageProvider.ERROR);
			return false;
		}
		setMessage(null, IMessageProvider.NONE);
		return true;
	}
}

Back to the top