Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f76592ca1124f85f55816a631913aa43f1e93dcc (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
/*******************************************************************************
 * Copyright (c) 2008, 2017 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.security.ui.storage.view;

import org.eclipse.equinox.internal.security.ui.Activator;
import org.eclipse.equinox.internal.security.ui.nls.SecUIMessages;
import org.eclipse.equinox.internal.security.ui.storage.IStorageConst;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;

public class NewNodeDialog extends TitleAreaDialog {

	private static final String HELP_ID = Activator.PLUGIN_ID + ".NewNodeDialog"; //$NON-NLS-1$

	protected Text nodeName;
	protected Button okButton;
	protected String name;

	public NewNodeDialog(Shell parentShell) {
		super(parentShell);
	}

	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText(SecUIMessages.newNodeTitle);
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, HELP_ID);
	}

	protected void createButtonsForButtonBar(Composite parent) {
		okButton = createButton(parent, IDialogConstants.OK_ID, SecUIMessages.newNodeOK, true);
		okButton.setEnabled(false);
		createButton(parent, IDialogConstants.CANCEL_ID, SecUIMessages.newNodeCancel, false);
	}

	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		setMessage(SecUIMessages.newNodeMsg);

		new Label(composite, SWT.LEFT).setText(SecUIMessages.newNodeLabel);
		nodeName = new Text(composite, SWT.LEFT | SWT.BORDER);
		nodeName.addModifyListener(event -> okButton.setEnabled(validName()));

		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		GridLayoutFactory.swtDefaults().generateLayout(composite);

		return composite;
	}

	protected boolean validName() {
		String tmp = nodeName.getText();
		boolean valid;
		if ((tmp == null) || (tmp.length() == 0))
			valid = false;
		else if (tmp.equals(IStorageConst.STORAGE_ID))
			valid = false;
		else
			valid = (tmp.indexOf('/') == -1);
		if (valid)
			setMessage(SecUIMessages.newNodeMsg, IMessageProvider.NONE);
		else
			setMessage(SecUIMessages.newNodeInvalid, IMessageProvider.ERROR);
		return valid;
	}

	protected void okPressed() {
		name = nodeName.getText();
		super.okPressed();
	}

	public String getNodeName() {
		return name;
	}

}

Back to the top