/*----------------------------------------------------------------------------- Copyright the original author or authors. Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -----------------------------------------------------------------------------*/ import org.aswing.border.EmptyBorder; import org.aswing.border.SimpleTitledBorder; import org.aswing.BorderLayout; import org.aswing.Container; import org.aswing.Event; import org.aswing.Insets; import org.aswing.JButton; import org.aswing.JCheckBox; import org.aswing.JLabel; import org.aswing.JList; import org.aswing.JPanel; import org.aswing.JScrollPane; import org.aswing.JTextField; import org.aswing.JWindow; import org.aswing.SoftBox; import net.customactions.asdk.log.Logger; import net.customactions.asdk.ui.dialog.alert.Alert; import net.customactions.aslicensor.event.EngineEvent; import net.customactions.aslicensor.event.LicensorModelListener; import net.customactions.aslicensor.mvc.LicensorModel; import net.customactions.aslicensor.mvc.LicensorView; /** * {@code MainView } class represents main AsLicensor view. * * <p>Use AsWing Framework * * @author Romain Ecarnot * @version 1.0 */ class net.customactions.aslicensor.mvc.view.MainView extends JWindow implements LicensorModelListener { //------------------------------------------------------------------------- // Public API //------------------------------------------------------------------------- /** * Constructs a new {@code MainView} instance based on {@code JWindow} * component. * * <p>An Alert dialog is prepared to receive Model notification. * Alert is based on ASDK Environment API. As we define in {@code LicensorMain} class, * SWF Studio strategy is selected to create Alert component. */ public function MainView(p_oParent : LicensorView) { super( p_oParent.getViewContainer() ); __oView = p_oParent; __oAlert = new Alert(); __oAlert.setButton(Alert.TYPE_OK); __createChildren(); __createBehaviour(); __layout(); } /** * Triggered when Model iterate over processing step * * @param p_oEvent {@code EngineEvent} instance */ public function onProgress(p_oEvent : EngineEvent) : Void { Logger.LOG(p_oEvent.getMessage()); } /** * Triggered when an problem occured during processing. * * @param p_oEvent {@code EngineEvent} instance */ public function onError(p_oEvent : EngineEvent) : Void { __enableUI(true); __oAlert.setTitle("Caution"); __oAlert.setIcon(Alert.ICON_EXCLAMATION); __oAlert.setMessage(p_oEvent.getMessage()); __oAlert.show(); } /** * Triggered when an error occured during processing. * * @param p_oEvent {@code EngineEvent} instance */ public function onStop(p_oEvent : EngineEvent) : Void { __enableUI(true); __oAlert.setTitle("Caution"); __oAlert.setIcon(Alert.ICON_STOP); __oAlert.setMessage(p_oEvent.getMessage()); __oAlert.show(); } /** * Triggered when process is complete. * * @param p_oEvent {@code EngineEvent} instance */ public function onComplete(p_oEvent : EngineEvent) : Void { __enableUI(true); __oAlert.setTitle("Complete"); __oAlert.setIcon(Alert.ICON_INFORMATION); __oAlert.setMessage(p_oEvent.getMessage()); __oAlert.show(); } /** * Triggered when license file is selected. * * @param p_oEvent {@code EngineEvent} instance */ public function onLicense(p_oEvent : EngineEvent) : Void { __txLicense.setText( p_oEvent.getMessage() ); } /** * Triggered when source folder is selected. * * @param p_oEvent {@code EngineEvent} instance */ public function onSource(p_oEvent : EngineEvent) : Void { __txSource.setText( p_oEvent.getMessage() ); } /** * Triggered when files listing is retreived from source folder. * * @param p_oEvent {@code EngineEvent} instance */ public function onList(p_oEvent : EngineEvent) : Void { var aFiles : Array = LicensorModel( p_oEvent.getTarget() ).getSourceFiles(); __oList.setListData(aFiles); __enableUI(true); } /*------------------------------------------------------------------------------------------*/ //------------------------------------------------------------------------- // Internal properties //------------------------------------------------------------------------- private var __oView : LicensorView; private var __lblLicense : JLabel; private var __txLicense : JTextField; private var __btnLicense : JButton; private var __lblSource : JLabel; private var __txSource : JTextField; private var __btnSource : JButton; private var __chkForce : JCheckBox; private var __btnCheck : JButton; private var __oList : JList; private var __btnProcess : JButton; private var __oAlert : Alert; //------------------------------------------------------------------------- // Private implementation //------------------------------------------------------------------------- /** * Creates Sub component using AsWing components */ private function __createChildren(Void) : Void { __lblLicense = new JLabel("License file "); __txLicense = new JTextField(); __txLicense.setEditable(false); __btnLicense = new JButton(" Browse "); __btnLicense.setToolTipText("Browse for license file"); __lblSource = new JLabel("Source folder"); __txSource = new JTextField(); __txSource.setEditable(false); __btnSource = new JButton("Browse"); __btnSource.setPreferredSize( __btnLicense.getPreferredSize() ); __btnSource.setToolTipText("Browse for source folder"); __chkForce = new JCheckBox("Force no tags implementation"); __btnCheck = new JButton("Check source files"); __oList = new JList([]); __oList.setOpaque(true); __btnProcess = new JButton("Process"); } /** * Creates components behaviour */ private function __createBehaviour(Void) : Void { __btnLicense.addEventListener(JButton.ON_RELEASE, __onLicenseClick, this); __btnSource.addEventListener(JButton.ON_RELEASE, __onSourceClick, this); __btnCheck.addEventListener(JButton.ON_RELEASE, __onCheckClick, this); __btnProcess.addEventListener(JButton.ON_RELEASE, __onProcessClick, this); } /** * Lays out components with AsWing layout / container architecture */ private function __layout(Void) : Void { var oWindowPane : Container = getContentPane(); oWindowPane.setLayout( new BorderLayout(0,5) ); oWindowPane.setBorder( new EmptyBorder(null, new Insets(10,5,10,5)) ); var oTopPane : Container = SoftBox.createVerticalBox(6); var oFirstLine : Container = new JPanel( new BorderLayout(5,0) ); oFirstLine.append(__lblLicense, BorderLayout.WEST); oFirstLine.append(__txLicense, BorderLayout.CENTER); oFirstLine.append(__btnLicense, BorderLayout.EAST); oTopPane.append(oFirstLine); var oSecondLine : Container = new JPanel( new BorderLayout(5, 0) ); __lblSource.setPreferredSize( __lblLicense.getPreferredSize() ); oSecondLine.append(__lblSource, BorderLayout.WEST); oSecondLine.append(__txSource, BorderLayout.CENTER); oSecondLine.append(__btnSource, BorderLayout.EAST); oTopPane.append(oSecondLine); __chkForce.setHorizontalAlignment(JCheckBox.LEFT); oTopPane.append(__chkForce); oTopPane.append(__btnCheck); oWindowPane.append(oTopPane, BorderLayout.NORTH); var oScrollPane : JScrollPane = new JScrollPane(__oList); oScrollPane.setBorder( new SimpleTitledBorder(null, "ActionScript files", SimpleTitledBorder.TOP, SimpleTitledBorder.LEFT) ); oWindowPane.append(oScrollPane, BorderLayout.CENTER); oWindowPane.append(__btnProcess, BorderLayout.SOUTH); } /** * Trigged when license button is clicked/ * * @param p_oEvent {@code Event} AsWing event instance */ private function __onLicenseClick(p_oEvent : Event) : Void { __oView.handleLicenseClick(); } /** * Trigged when source button is clicked/ * * @param p_oEvent {@code Event} AsWing event instance */ private function __onSourceClick(p_oEvent : Event) : Void { __oView.handleSourceClick(); } /** * Trigged when check button is clicked/ * * @param p_oEvent {@code Event} AsWing event instance */ private function __onCheckClick(p_oEvent : Event) : Void { __enableUI(false); __oView.handleCheckClick(); } /** * Trigged when process button is clicked/ * * @param p_oEvent {@code Event} AsWing event instance */ private function __onProcessClick(p_oEvent : Event) : Void { __enableUI(false); __oView.handleProcessClick(); } /** * Toggles UI interactivity * * @param p_bEnable {@code true} to enable UI, otherwise {@code false} * to disable it */ private function __enableUI(p_bEnable : Boolean) : Void { __btnLicense.setEnabled(p_bEnable); __btnSource.setEnabled(p_bEnable); __chkForce.setEnabled(p_bEnable); __btnCheck.setEnabled(p_bEnable); __btnProcess.setEnabled(p_bEnable); __oList.setEnabled(p_bEnable); } }