blob: 9058ed0da08329f264d3e4e48c94f1b5ee3c3a81 [file] [log] [blame]
david_williams96213482004-11-11 09:07:12 +00001/*******************************************************************************
2 * Copyright (c) 2001, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
david_williamsf3680f02005-04-13 22:43:54 +000013package org.eclipse.wst.xml.ui.internal.dialogs;
david_williams96213482004-11-11 09:07:12 +000014
15import org.eclipse.jface.dialogs.Dialog;
16import org.eclipse.jface.dialogs.IDialogConstants;
17import org.eclipse.swt.SWT;
18import org.eclipse.swt.layout.GridData;
19import org.eclipse.swt.layout.GridLayout;
20import org.eclipse.swt.widgets.Button;
21import org.eclipse.swt.widgets.Composite;
22import org.eclipse.swt.widgets.Control;
23import org.eclipse.swt.widgets.Label;
24import org.eclipse.swt.widgets.Shell;
25import org.eclipse.swt.widgets.Text;
26import org.eclipse.ui.help.WorkbenchHelp;
david_williams5f2420f2005-04-12 12:23:57 +000027import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
david_williamsf3680f02005-04-13 22:43:54 +000028import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds;
david_williams96213482004-11-11 09:07:12 +000029import org.w3c.dom.ProcessingInstruction;
30
david_williams96213482004-11-11 09:07:12 +000031public class EditProcessingInstructionDialog extends Dialog {
32 protected String data;
33 protected Text dataField;
34 protected String target;
35 protected Text targetField;
36
37 public EditProcessingInstructionDialog(Shell parentShell, ProcessingInstruction pi) {
38 this(parentShell, pi.getTarget(), pi.getData());
39 }
40
41 public EditProcessingInstructionDialog(Shell parentShell, String target, String data) {
42 super(parentShell);
43 setShellStyle(getShellStyle() | SWT.RESIZE);
44 this.target = target;
45 this.data = data;
46 }
47
48 protected void buttonPressed(int buttonId) {
49 target = getModelValue(targetField.getText());
50 data = getModelValue(dataField.getText());
51 super.buttonPressed(buttonId);
52 }
53
54 protected void createButtonsForButtonBar(Composite parent) {
55 Button okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
56 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
57 }
58
59 protected Control createDialogArea(Composite parent) {
60 Composite dialogArea = (Composite) super.createDialogArea(parent);
61 WorkbenchHelp.setHelp(dialogArea, XMLCommonUIContextIds.XCUI_PROCESSING_DIALOG);
62
63 Composite composite = new Composite(dialogArea, SWT.NONE);
64 GridLayout layout = new GridLayout();
65 layout.numColumns = 2;
66 layout.marginWidth = 0;
67 composite.setLayout(layout);
68 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
69
70
71 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
72 gd.widthHint = 250;
73
74 Label targetLabel = new Label(composite, SWT.NONE);
david_williams5f2420f2005-04-12 12:23:57 +000075 targetLabel.setText(XMLUIMessages._UI_LABEL_TARGET_COLON); //$NON-NLS-1$
david_williams96213482004-11-11 09:07:12 +000076
77 targetField = new Text(composite, SWT.SINGLE | SWT.BORDER);
78 targetField.setLayoutData(gd);
79 targetField.setText(getDisplayValue(target));
80
81 Label dataLabel = new Label(composite, SWT.NONE);
david_williams5f2420f2005-04-12 12:23:57 +000082 dataLabel.setText(XMLUIMessages._UI_LABEL_DATA_COLON); //$NON-NLS-1$
david_williams96213482004-11-11 09:07:12 +000083
84 dataField = new Text(composite, SWT.SINGLE | SWT.BORDER);
85 dataField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
86 dataField.setText(getDisplayValue(data));
87
88 return dialogArea;
89 }
90
91 protected Label createMessageArea(Composite composite) {
92 Label label = new Label(composite, SWT.NONE);
93 //label.setText(message);
94 return label;
95 }
96
97 public String getData() {
98 return data;
99 }
100
101 protected String getDisplayValue(String string) {
102 return string != null ? string : ""; //$NON-NLS-1$
103 }
104
105 protected String getModelValue(String string) {
106 String result = null;
107 if (string != null && string.trim().length() > 0) {
108 result = string;
109 }
110 return result;
111 }
112
113
114 public String getTarget() {
115 return target;
116 }
117}
118
119
120