david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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_williams | f3680f0 | 2005-04-13 22:43:54 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.xml.ui.internal.dialogs; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 14 | |
| 15 | import org.eclipse.jface.dialogs.Dialog; |
| 16 | import org.eclipse.jface.dialogs.IDialogConstants; |
| 17 | import org.eclipse.swt.SWT; |
| 18 | import org.eclipse.swt.layout.GridData; |
| 19 | import org.eclipse.swt.layout.GridLayout; |
| 20 | import org.eclipse.swt.widgets.Button; |
| 21 | import org.eclipse.swt.widgets.Composite; |
| 22 | import org.eclipse.swt.widgets.Control; |
| 23 | import org.eclipse.swt.widgets.Label; |
| 24 | import org.eclipse.swt.widgets.Shell; |
| 25 | import org.eclipse.swt.widgets.Text; |
| 26 | import org.eclipse.ui.help.WorkbenchHelp; |
david_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 27 | import org.eclipse.wst.xml.ui.internal.XMLUIMessages; |
david_williams | f3680f0 | 2005-04-13 22:43:54 +0000 | [diff] [blame] | 28 | import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 29 | import org.w3c.dom.ProcessingInstruction; |
| 30 | |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 31 | public 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_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 75 | targetLabel.setText(XMLUIMessages._UI_LABEL_TARGET_COLON); //$NON-NLS-1$ |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 76 | |
| 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_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 82 | dataLabel.setText(XMLUIMessages._UI_LABEL_DATA_COLON); //$NON-NLS-1$ |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 83 | |
| 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 | |