add remote tab to the enviroment tab
authorcperkonig <cperkonig>
Wed, 11 Feb 2004 22:19:46 +0000 (22:19 +0000)
committercperkonig <cperkonig>
Wed, 11 Feb 2004 22:19:46 +0000 (22:19 +0000)
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEnvironmentTab.java

index 68bc0f4..041a5d5 100644 (file)
@@ -3,6 +3,8 @@ package net.sourceforge.phpdt.internal.debug.ui.launcher;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
@@ -20,6 +22,8 @@ import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
 import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -35,6 +39,10 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.TabFolder;
 import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.internal.dialogs.ListContentProvider;
 
 public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
@@ -42,7 +50,52 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
        protected java.util.List installedInterpretersWorkingCopy;
        protected Combo interpreterCombo;
        protected Button loadPathDefaultButton;
+       protected Button fRemoteDebugCheckBox;
+       protected Button fFileMapRemoveButton;
+       protected Button fFileMapAddButton;
+       protected Button fFileMapEditButton;
+       protected Text fRemoteSourcePath;
+       protected Table fRemoteDebugFileMapTable;
+       protected TabFolder tabFolder;
+       
+       private class RemoteDebugTabListener extends SelectionAdapter implements ModifyListener {
+
+               /* (non-Javadoc)
+                * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+                */
+               public void modifyText(ModifyEvent e) {
+                       updateLaunchConfigurationDialog();
+               }
+               
+               /* (non-Javadoc)
+                * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+                */
+               public void widgetSelected(SelectionEvent e) {
+                       Object source= e.getSource();
+                       if (source == fRemoteDebugFileMapTable) {
+                               setFileMapButtonsEnableState();
+                       } else if (source == fFileMapAddButton) {
+                               handleFileMapAddButtonSelected();
+                       } else if (source == fFileMapEditButton) {
+                               handleFileMapEditButtonSelected();
+                       } else if (source == fFileMapRemoveButton) {
+                               handleFileMapRemoveButtonSelected();
+                       } else if (source == fRemoteDebugCheckBox) {
+                               setRemoteTabEnableState();              
+                       } else {
+                               updateLaunchConfigurationDialog();;
+               }
+                       
+               }
 
+       }
+       
+       private RemoteDebugTabListener fListener= new RemoteDebugTabListener();
+       
+       private static final boolean DEFAULT_REMOTE_DEBUG= false;
+       static String [] columnTitles   = { PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMapTableTitle.local"),
+                                                                                                                                               PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMapTableTitle.remote")
+                                                                                                                                       };
        public PHPEnvironmentTab() {
                super();
        }
@@ -50,13 +103,166 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
        public void createControl(Composite parent) {
                Composite composite = createPageRoot(parent);
 
-               TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
+               tabFolder = new TabFolder(composite, SWT.NONE);
                GridData gridData = new GridData(GridData.FILL_BOTH);
                tabFolder.setLayoutData(gridData);
 
                addLoadPathTab(tabFolder);
                addInterpreterTab(tabFolder);
+               addRemoteDebugTab(tabFolder);
+       }
+       
+       protected void addRemoteDebugTab(TabFolder tabFolder)
+       {
+               Label label;
+                               
+               TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
+               remoteDebugTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
+               
+               Composite comp = new Composite(tabFolder, SWT.NONE);
+               comp.setLayout(new GridLayout());       
+               remoteDebugTab.setControl(comp);                
+               GridData gd;
+               
+               fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
+               fRemoteDebugCheckBox.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
+               fRemoteDebugCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+               fRemoteDebugCheckBox.addSelectionListener(fListener);
+               
+               label = new Label(comp, SWT.NONE);
+               label.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
+               fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
+               gd = new GridData(GridData.FILL_HORIZONTAL);
+               fRemoteSourcePath.setLayoutData(gd);            
+               fRemoteSourcePath.addModifyListener(fListener);
+               
+               createVerticalSpacer(comp,1);
+               
+               Composite fileMapComp = new Composite(comp, SWT.NONE);
+               gd = new GridData(GridData.FILL_BOTH);
+               fileMapComp.setLayoutData(gd);
+               GridLayout parametersLayout = new GridLayout();
+               parametersLayout.numColumns = 2;
+               parametersLayout.marginHeight = 0;
+               parametersLayout.marginWidth = 0;
+               fileMapComp.setLayout(parametersLayout);
+
+               
+               Label fileMapLabel = new Label(fileMapComp, SWT.NONE);
+               fileMapLabel.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.label"));
+               gd = new GridData();
+               gd.horizontalSpan = 2;
+               fileMapLabel.setLayoutData(gd);
+
+               
+               fRemoteDebugFileMapTable = new Table(fileMapComp, SWT.BORDER | SWT.MULTI);
+               TableLayout tableLayout = new TableLayout();
+               fRemoteDebugFileMapTable.setLayout(tableLayout);
+
+               gd = new GridData(GridData.FILL_BOTH);
+               fRemoteDebugFileMapTable.setLayoutData(gd);
+               TableColumn column1 = new TableColumn(this.fRemoteDebugFileMapTable, SWT.NONE);
+               column1.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.Table.Title.local")); //$NON-NLS-1$
+               TableColumn column2 = new TableColumn(this.fRemoteDebugFileMapTable, SWT.NONE);
+               column2.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.Table.Title.remote"));                //$NON-NLS-1$
+               tableLayout.addColumnData(new ColumnWeightData(100));
+               tableLayout.addColumnData(new ColumnWeightData(100));
+               fRemoteDebugFileMapTable.setHeaderVisible(true);
+               fRemoteDebugFileMapTable.setLinesVisible(true);
+               fRemoteDebugFileMapTable.addSelectionListener(fListener);
+               fRemoteDebugFileMapTable.setEnabled(false);             
+       
+               Composite envButtonComp = new Composite(fileMapComp, SWT.NONE);
+               GridLayout envButtonLayout = new GridLayout();
+               envButtonLayout.marginHeight = 0;
+               envButtonLayout.marginWidth = 0;
+               envButtonComp.setLayout(envButtonLayout);
+               gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
+               envButtonComp.setLayoutData(gd);
+
+               
+               fFileMapAddButton = createPushButton(envButtonComp ,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.Button.Add.label"), null); //$NON-NLS-1$
+               fFileMapAddButton.addSelectionListener(fListener);
+               fFileMapAddButton.setEnabled(false);
+               
+               fFileMapEditButton = createPushButton(envButtonComp,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.Button.Edit.label"), null); //$NON-NLS-1$
+               fFileMapEditButton.addSelectionListener(fListener);
+               fFileMapEditButton.setEnabled(false);
+               
+               fFileMapRemoveButton = createPushButton(envButtonComp,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.FileMap.Button.Remove.label"), null); //$NON-NLS-1$
+               fFileMapRemoveButton.addSelectionListener(fListener);
+               fFileMapRemoveButton.setEnabled(false);
+       
+
+       }
+       
+       void handleFileMapAddButtonSelected()
+       {
+               TableItem item = new TableItem (fRemoteDebugFileMapTable, SWT.NONE);
+               updateLaunchConfigurationDialog();
+       }
+       
+       void handleFileMapRemoveButtonSelected()
+       {
+               int idx=fRemoteDebugFileMapTable.getSelectionIndex();
+               if (idx !=-1)
+               fRemoteDebugFileMapTable.remove(idx);
+               updateLaunchConfigurationDialog();
        }
+       
+       void handleFileMapEditButtonSelected()
+       {
+       }
+
+
+       /**
+        * Set the enabled state of whole tab.
+        */
+       private void setRemoteTabEnableState() {
+               boolean state=fRemoteDebugCheckBox.getSelection();
+               fRemoteSourcePath.setEnabled(state);
+               
+//     TODO: (cperkonig)       not implemented yet             
+//             fRemoteDebugFileMapTable.setEnabled(state);
+//             if (!state)
+//             {
+//                     fFileMapEditButton.setEnabled(false);
+//                     fFileMapRemoveButton.setEnabled(false);         
+//                     fFileMapAddButton.setEnabled(false);
+//             } else {
+//                     setFileMapButtonsEnableState();
+//             }
+
+               updateLaunchConfigurationDialog();
+       }
+       
+       
+       /**
+        * Set the enabled state of the three environment variable-related buttons based on the
+        * selection in the FileMapTable widget.
+        */
+       private void setFileMapButtonsEnableState() {
+//     just do nothing for now
+//
+               if(fRemoteDebugCheckBox.getSelection())
+               {
+                       int selectCount = this.fRemoteDebugFileMapTable.getSelectionIndices().length;
+                       if (selectCount < 1) {
+                               fFileMapEditButton.setEnabled(false);
+                               fFileMapRemoveButton.setEnabled(false);
+                       } else {
+                               fFileMapRemoveButton.setEnabled(true);
+                               if (selectCount == 1) {
+                                       fFileMapEditButton.setEnabled(true);
+                               } else {
+                                       fFileMapEditButton.setEnabled(false);
+                               }
+                       }               
+                       fFileMapAddButton.setEnabled(true);
+               }
+       }
+       
+       
 
        protected void addLoadPathTab(TabFolder tabFolder) {
                Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
@@ -87,6 +293,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                        }
                };
        }
+       
+       
 
        protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
                return new SelectionAdapter() {
@@ -154,7 +362,58 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
        public void initializeFrom(ILaunchConfiguration configuration) {
                initializeLoadPath(configuration);
                initializeInterpreterSelection(configuration);
+               initializeRemoteDebug(configuration);
        }
+       
+       protected void initializeRemoteDebug(ILaunchConfiguration configuration)
+       {
+               String s[];
+               int startIdx =0;
+               int idx;
+               try{
+                       fRemoteDebugCheckBox.setSelection(
+                               configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,DEFAULT_REMOTE_DEBUG));
+               } catch(CoreException ce) {
+                       fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
+               }
+               setRemoteTabEnableState();
+               try{
+                       fRemoteSourcePath.setText(
+                                       configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,""));
+               } catch(CoreException ce) {
+                       fRemoteSourcePath.setText("");
+               }
+                       
+               updateFileMapFromConfig(configuration);
+                
+       }
+       
+       private void updateFileMapFromConfig(ILaunchConfiguration config) {
+                       Map envVars = null;
+                       try {
+                               if (config != null) {
+                                       envVars = config.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
+                               }
+                               updateFileMapTable(envVars, this.fRemoteDebugFileMapTable);
+                               setFileMapButtonsEnableState();
+                       } catch (CoreException ce) {
+                               log(ce);
+                       }
+               }
+
+               private void updateFileMapTable(Map map, Table tableWidget) {
+                       tableWidget.removeAll();
+                       if (map == null) {
+                               return;
+                       }
+                       Iterator iterator = map.keySet().iterator();
+                       while (iterator.hasNext()) {
+                               String key = (String) iterator.next();
+                               String value = (String) map.get(key);
+                               TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
+                               tableItem.setText(new String[] {key, value});                   
+                       }
+               }
 
        protected void initializeLoadPath(ILaunchConfiguration configuration) {
                boolean useDefaultLoadPath = true;
@@ -224,6 +483,10 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                        }
                        configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH, loadPathStrings);
                }
+               
+               configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG, fRemoteDebugCheckBox.getSelection());
+               configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, getMapFromFileMapTable());         
+               configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, fRemoteSourcePath.getText());
        }
 
        protected Composite createPageRoot(Composite parent) {
@@ -236,6 +499,21 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
                return composite;
        }
+       
+       private Map getMapFromFileMapTable() {
+               TableItem[] items = fRemoteDebugFileMapTable.getItems();
+               if (items.length == 0) {
+                       return null;
+               }
+               Map map = new HashMap(items.length);
+               for (int i = 0; i < items.length; i++) {
+                       TableItem item = items[i];
+                       String key = item.getText(0);
+                       String value = item.getText(1);
+                       map.put(key, value);
+               }               
+               return map;
+       }
 
        public String getName() {
                return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.name");