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 @Override
071 public void modifyText(ModifyEvent event) {
072 if (javaPath.getText().trim().length() == 0)
073 updateStatus(ProjectUtil.createErrorStatus("Tempate URI is mandatory"));
074 else
075 updateStatus(new Status(IStatus.OK, GraniteActivator.PLUGIN_ID, ""));
076 }
077 });
078
079 label = new Label(composite, SWT.NONE);
080 label.setText("ActionScript3 Path (eg: my.translated.path):");
081
082 as3Path = new Text(composite, SWT.BORDER);
083 as3Path.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
084 if (initialAs3Path != null)
085 as3Path.setText(initialAs3Path);
086
087 applyDialogFont(composite);
088 return composite;
089 }
090
091 @Override
092 protected void okPressed() {
093 if (javaPath.getText().trim().length() == 0 || as3Path.getText().trim().length() == 0)
094 updateStatus(ProjectUtil.createErrorStatus("Java and As3 path are mandatory"));
095 else
096 super.okPressed();
097 }
098
099 @Override
100 protected void computeResult() {
101 setSelectionResult(new String[]{javaPath.getText().trim(), as3Path.getText().trim()});
102 }
103
104 @Override
105 protected void cancelPressed() {
106 setSelectionResult(null);
107 super.cancelPressed();
108 }
109 }