001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2007-2010 ADEQUATE SYSTEMS SARL
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.builder.ui;
022
023 import org.eclipse.core.runtime.IStatus;
024 import org.eclipse.core.runtime.Status;
025 import org.eclipse.swt.SWT;
026 import org.eclipse.swt.events.ModifyEvent;
027 import org.eclipse.swt.events.ModifyListener;
028 import org.eclipse.swt.layout.GridData;
029 import org.eclipse.swt.widgets.Composite;
030 import org.eclipse.swt.widgets.Control;
031 import org.eclipse.swt.widgets.Label;
032 import org.eclipse.swt.widgets.Shell;
033 import org.eclipse.swt.widgets.Text;
034 import org.eclipse.ui.dialogs.SelectionStatusDialog;
035 import org.granite.builder.GraniteActivator;
036 import org.granite.builder.util.ProjectUtil;
037
038 /**
039 * @author Franck WOLFF
040 */
041 public class TemplateUrisDialog extends SelectionStatusDialog {
042
043 private final String initialTemplateUri;
044 private final String initialBaseTemplateUri;
045
046 private Text templateUri = null;
047 private Text baseTemplateUri = null;
048
049 public TemplateUrisDialog(Shell parent, String initialTemplateUri, String initialBaseTemplateUri) {
050 super(parent);
051 this.initialTemplateUri = initialTemplateUri;
052 this.initialBaseTemplateUri = initialBaseTemplateUri;
053 }
054
055 @Override
056 protected Control createDialogArea(Composite parent) {
057 Composite composite = (Composite)super.createDialogArea(parent);
058 GridData data = new GridData(GridData.FILL_BOTH);
059 data.widthHint = convertWidthInCharsToPixels(70);
060 composite.setLayoutData(data);
061
062 Label label = new Label(composite, SWT.NONE);
063 label.setText("Template URI:");
064
065 templateUri = new Text(composite, SWT.BORDER);
066 templateUri.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
067 if (initialTemplateUri != null)
068 templateUri.setText(initialTemplateUri);
069 templateUri.addModifyListener(new ModifyListener() {
070 public void modifyText(ModifyEvent event) {
071 if (templateUri.getText().trim().length() == 0)
072 updateStatus(ProjectUtil.createErrorStatus("Tempate URI is mandatory"));
073 else
074 updateStatus(new Status(IStatus.OK, GraniteActivator.PLUGIN_ID, ""));
075 }
076 });
077
078 label = new Label(composite, SWT.NONE);
079 label.setText("Base template URI (optional):");
080
081 baseTemplateUri = new Text(composite, SWT.BORDER);
082 baseTemplateUri.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
083 if (initialBaseTemplateUri != null)
084 baseTemplateUri.setText(initialBaseTemplateUri);
085
086 applyDialogFont(composite);
087 return composite;
088 }
089
090 @Override
091 protected void okPressed() {
092 if (templateUri.getText().trim().length() == 0)
093 updateStatus(ProjectUtil.createErrorStatus("Tempate URI is mandatory"));
094 else
095 super.okPressed();
096 }
097
098 @Override
099 protected void computeResult() {
100 setSelectionResult(new String[]{templateUri.getText().trim(), baseTemplateUri.getText().trim()});
101 }
102
103 @Override
104 protected void cancelPressed() {
105 setSelectionResult(null);
106 super.cancelPressed();
107 }
108 }