LocalMapReduceLaunchTabGroup.java
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:7k
源码类别:

网格计算

开发平台:

Java

  1. /**
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements.  See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership.  The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License.  You may obtain a copy of the License at
  9.  *
  10.  *     http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing, software
  13.  * distributed under the License is distributed on an "AS IS" BASIS,
  14.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15.  * See the License for the specific language governing permissions and
  16.  * limitations under the License.
  17.  */
  18. package org.apache.hadoop.eclipse.launch;
  19. import org.eclipse.core.runtime.CoreException;
  20. import org.eclipse.debug.core.ILaunchConfiguration;
  21. import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  22. import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
  23. import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
  24. import org.eclipse.debug.ui.CommonTab;
  25. import org.eclipse.debug.ui.ILaunchConfigurationDialog;
  26. import org.eclipse.debug.ui.ILaunchConfigurationTab;
  27. import org.eclipse.jdt.core.IType;
  28. import org.eclipse.jdt.core.JavaModelException;
  29. import org.eclipse.jdt.core.dom.AST;
  30. import org.eclipse.jdt.core.search.SearchEngine;
  31. import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;
  32. import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
  33. import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
  34. import org.eclipse.jdt.ui.IJavaElementSearchConstants;
  35. import org.eclipse.jdt.ui.JavaUI;
  36. import org.eclipse.jface.dialogs.ProgressMonitorDialog;
  37. import org.eclipse.jface.window.Window;
  38. import org.eclipse.swt.SWT;
  39. import org.eclipse.swt.layout.GridData;
  40. import org.eclipse.swt.layout.GridLayout;
  41. import org.eclipse.swt.widgets.Button;
  42. import org.eclipse.swt.widgets.Composite;
  43. import org.eclipse.swt.widgets.Event;
  44. import org.eclipse.swt.widgets.Label;
  45. import org.eclipse.swt.widgets.Listener;
  46. import org.eclipse.swt.widgets.Text;
  47. import org.eclipse.ui.dialogs.SelectionDialog;
  48. /**
  49.  * 
  50.  * Handler for Local MapReduce job launches
  51.  * 
  52.  * TODO(jz) this may not be needed as we almost always deploy to a remote server
  53.  * and not locally, where we do do it locally we may just be able to exec
  54.  * scripts without going to java
  55.  * 
  56.  */
  57. public class LocalMapReduceLaunchTabGroup extends
  58.     AbstractLaunchConfigurationTabGroup {
  59.   public LocalMapReduceLaunchTabGroup() {
  60.     // TODO Auto-generated constructor stub
  61.   }
  62.   public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
  63.     setTabs(new ILaunchConfigurationTab[] { new MapReduceLaunchTab(),
  64.         new JavaArgumentsTab(), new JavaJRETab(), new JavaClasspathTab(),
  65.         new CommonTab() });
  66.   }
  67.   public static class MapReduceLaunchTab extends AbstractLaunchConfigurationTab {
  68.     private Text combinerClass;
  69.     private Text reducerClass;
  70.     private Text mapperClass;
  71.     @Override
  72.     public boolean canSave() {
  73.       return true;
  74.     }
  75.     @Override
  76.     public boolean isValid(ILaunchConfiguration launchConfig) {
  77.       // todo: only if all classes are of proper types
  78.       return true;
  79.     }
  80.     public void createControl(final Composite parent) {
  81.       Composite panel = new Composite(parent, SWT.NONE);
  82.       GridLayout layout = new GridLayout(3, false);
  83.       panel.setLayout(layout);
  84.       Label mapperLabel = new Label(panel, SWT.NONE);
  85.       mapperLabel.setText("Mapper");
  86.       mapperClass = new Text(panel, SWT.SINGLE | SWT.BORDER);
  87.       createRow(parent, panel, mapperClass);
  88.       Label reducerLabel = new Label(panel, SWT.NONE);
  89.       reducerLabel.setText("Reducer");
  90.       reducerClass = new Text(panel, SWT.SINGLE | SWT.BORDER);
  91.       createRow(parent, panel, reducerClass);
  92.       Label combinerLabel = new Label(panel, SWT.NONE);
  93.       combinerLabel.setText("Combiner");
  94.       combinerClass = new Text(panel, SWT.SINGLE | SWT.BORDER);
  95.       createRow(parent, panel, combinerClass);
  96.       panel.pack();
  97.       setControl(panel);
  98.     }
  99.     private void createRow(final Composite parent, Composite panel,
  100.         final Text text) {
  101.       text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  102.       Button button = new Button(panel, SWT.BORDER);
  103.       button.setText("Browse...");
  104.       button.addListener(SWT.Selection, new Listener() {
  105.         public void handleEvent(Event arg0) {
  106.           try {
  107.             AST ast = AST.newAST(3);
  108.             SelectionDialog dialog = JavaUI.createTypeDialog(parent.getShell(),
  109.                 new ProgressMonitorDialog(parent.getShell()), SearchEngine
  110.                     .createWorkspaceScope(),
  111.                 IJavaElementSearchConstants.CONSIDER_CLASSES, false);
  112.             dialog.setMessage("Select Mapper type (implementing )");
  113.             dialog.setBlockOnOpen(true);
  114.             dialog.setTitle("Select Mapper Type");
  115.             dialog.open();
  116.             if ((dialog.getReturnCode() == Window.OK)
  117.                 && (dialog.getResult().length > 0)) {
  118.               IType type = (IType) dialog.getResult()[0];
  119.               text.setText(type.getFullyQualifiedName());
  120.               setDirty(true);
  121.             }
  122.           } catch (JavaModelException e) {
  123.             // TODO Auto-generated catch block
  124.             e.printStackTrace();
  125.           }
  126.         }
  127.       });
  128.     }
  129.     public String getName() {
  130.       return "Hadoop";
  131.     }
  132.     public void initializeFrom(ILaunchConfiguration configuration) {
  133.       try {
  134.         mapperClass.setText(configuration.getAttribute(
  135.             "org.apache.hadoop.eclipse.launch.mapper", ""));
  136.         reducerClass.setText(configuration.getAttribute(
  137.             "org.apache.hadoop.eclipse.launch.reducer", ""));
  138.         combinerClass.setText(configuration.getAttribute(
  139.             "org.apache.hadoop.eclipse.launch.combiner", ""));
  140.       } catch (CoreException e) {
  141.         // TODO Auto-generated catch block
  142.         e.printStackTrace();
  143.         setErrorMessage(e.getMessage());
  144.       }
  145.     }
  146.     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
  147.       configuration.setAttribute("org.apache.hadoop.eclipse.launch.mapper",
  148.           mapperClass.getText());
  149.       configuration.setAttribute(
  150.           "org.apache.hadoop.eclipse.launch.reducer", reducerClass
  151.               .getText());
  152.       configuration.setAttribute(
  153.           "org.apache.hadoop.eclipse.launch.combiner", combinerClass
  154.               .getText());
  155.     }
  156.     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
  157.     }
  158.   }
  159. }