001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
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 PackageTranslatorDialog extends SelectionStatusDialog {
042
043 private final String initialJavaPath;
044 private final String initialAs3Path;
045
046 private Text javaPath = null;
047 private Text as3Path = null;
048
049 public PackageTranslatorDialog(Shell parent, String initialJavaPath, String initialAs3Path) {
050 super(parent);
051 this.initialJavaPath = initialJavaPath;
052 this.initialAs3Path = initialAs3Path;
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("Java Path (eg: my.path):");
064
065 javaPath = new Text(composite, SWT.BORDER);
066 javaPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
067 if (initialJavaPath != null)
068 javaPath.setText(initialJavaPath);
069 javaPath.addModifyListener(new ModifyListener() {
070 public void modifyText(ModifyEvent event) {
071 if (javaPath.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("ActionScript3 Path (eg: my.translated.path):");
080
081 as3Path = new Text(composite, SWT.BORDER);
082 as3Path.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
083 if (initialAs3Path != null)
084 as3Path.setText(initialAs3Path);
085
086 applyDialogFont(composite);
087 return composite;
088 }
089
090 @Override
091 protected void okPressed() {
092 if (javaPath.getText().trim().length() == 0 || as3Path.getText().trim().length() == 0)
093 updateStatus(ProjectUtil.createErrorStatus("Java and As3 path are mandatory"));
094 else
095 super.okPressed();
096 }
097
098 @Override
099 protected void computeResult() {
100 setSelectionResult(new String[]{javaPath.getText().trim(), as3Path.getText().trim()});
101 }
102
103 @Override
104 protected void cancelPressed() {
105 setSelectionResult(null);
106 super.cancelPressed();
107 }
108 }