⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argumentstab.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        data = new GridData ();
        data.horizontalSpan = 2;
        data.horizontalAlignment = GridData.FILL;
        buttonSeeResultingCommandLine.setLayoutData (data);
        buttonSeeResultingCommandLine.addSelectionListener(this.listener);
        
        text = new Text (comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        text.setText ("In case you are in doubt how will the run happen, click the button to \n" +
                      "see the command-line that will be executed with the current parameters\n" +
                      "(and the PYTHONPATH / CLASSPATH used for the run).");
        data = new GridData ();
        data.grabExcessVerticalSpace = true;
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.FILL;
        data.horizontalSpan = 1;
        data.verticalSpan = 5;
        text.setLayoutData (data);
        
    }


    
    /**
     * checks if some launch is valid 
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
     */
    public boolean isValid(ILaunchConfiguration launchConfig) {
        setErrorMessage(null);
        setMessage(null);
        String interpreter;
        try {
            interpreter = launchConfig.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT);
        } catch (CoreException e) {
            setErrorMessage("No interpreter? " + e.getMessage());
            return false;
        }
        if(interpreter == null){
            return false;
        }
        
        try {
            return checkIfInterpreterExists(interpreter);
            
        } catch (Exception e) {
            //we might have problems getting the configured interpreters
            setMessage(e.getMessage());
            setErrorMessage(e.getMessage());
            return false;
        }
    }

    /**
     * this is the name that will appear to the user 
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
     */
    public String getName() {
        return "Arguments";
    }

    /**
     * this is the image that will appear to the user 
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
     */
    public Image getImage() {
        return PydevPlugin.getImageCache().get(Constants.MAIN_ICON);
    }
    
    public void setDefaults(ILaunchConfigurationWorkingCopy arg0) {
        //no defaults to set
    }

    /**
     * Initializes widgets from ILaunchConfiguration
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
     */
    public void initializeFrom(ILaunchConfiguration conf) {
        try {
            workingCopyForCommandLineGeneration = conf.getWorkingCopy();
        } catch (CoreException e1) {
            throw new RuntimeException(e1);
        }
                
        String baseDirectory = "";
        String interpreter = "";
        String arguments = "";
        String vmArguments = "";
        try {
            baseDirectory = conf.getAttribute(Constants.ATTR_WORKING_DIRECTORY, "");
            interpreter = conf.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT);
            vmArguments = conf.getAttribute(Constants.ATTR_VM_ARGUMENTS,"");
            arguments = conf.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, "");
        }
        catch (CoreException e) {
        }
        vmArgumentsField.setText(vmArguments);
        baseDirectoryField.setText(baseDirectory);
        programArgumentField.setText(arguments);
        String[] interpreters = interpreterComboField.getItems();
        
        if(interpreters.length == 0){
            setErrorMessage("No interpreter is configured, please, go to window > preferences > interpreters and add the interpreter you want to use.");
        }else{
        
            int selectThis = -1;
            
            if (interpreter.equals(Constants.ATTR_INTERPRETER_DEFAULT))
            {
            	selectThis = 0;
            }
            else {
            	for (int i=1; i< interpreters.length; i++){
            		if (interpreter.equals(interpreters[i])){
            			selectThis = i;
            			break;
            		}
            	}
            }
            
            if (selectThis == -1) {
            	if (interpreter.startsWith("${")) {
            		interpreterComboField.setText(interpreter);
            	}else{
            		setErrorMessage("Obsolete interpreter is selected. Choose a new one.");
            	}
            }else{
                interpreterComboField.select(selectThis);
            }
        }
        
        try {
            PythonRunnerConfig config = getConfig(conf, getLaunchConfigurationDialog());
            mainModuleTab.updatePythonpath(config.pythonpathUsed);
        } catch (CoreException e) {
            PydevPlugin.log(e);
        }

    }
    
    /**
     * save the values 
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
     */
    public void performApply(ILaunchConfigurationWorkingCopy conf) {
        String value;        

        value = baseDirectoryField.getText().trim();
        setAttribute(conf, Constants.ATTR_WORKING_DIRECTORY, value);
        
        value = programArgumentField.getText().trim();
        setAttribute(conf, Constants.ATTR_PROGRAM_ARGUMENTS, value);
        
        value = vmArgumentsField.getText().trim();
        setAttribute(conf, Constants.ATTR_VM_ARGUMENTS, value);
        
        if (interpreterComboField.getSelectionIndex() == 0){
        	// The default was selected
        	value = Constants.ATTR_INTERPRETER_DEFAULT;
        	
        }else{
        	value = interpreterComboField.getText();
        }
        setAttribute(conf, Constants.ATTR_INTERPRETER, value);

        try {
            PythonRunnerConfig config = getConfig(conf, getLaunchConfigurationDialog());
            mainModuleTab.updatePythonpath(config.pythonpathUsed);
        } catch (CoreException e) {
            PydevPlugin.log(e);
        }
    }
    
    /**
     * @param interpreter the interpreter to validate
     * @return true if the interpreter is configured in pydev
     */
    protected boolean checkIfInterpreterExists(String interpreter) {
    	if (interpreter.equals(Constants.ATTR_INTERPRETER_DEFAULT))	{
    	    if(this.interpreterManager.getDefaultInterpreter() != null){
    			// The default interpreter is selected, and we have a default interpreter
	    		return true;
	    	}
	    	//otherwise, the default is selected, but we have no default
	    	return false;
    	}
    	
        String[] interpreters = this.interpreterManager.getInterpreters();
        for (int i = 0; i < interpreters.length; i++) {
            if (interpreters[i] != null && interpreters[i].equals(interpreter)) {
                return true;
            }
        }
        if(interpreter.startsWith("${")){
        	return true;
        }
        return false;
    }
    
    /**
     * sets attributes in the working copy
     */
    private void setAttribute(ILaunchConfigurationWorkingCopy conf, String name, String value) {
        if (value == null || value.length() == 0){
            conf.setAttribute(name, (String)null);
        }else{
            conf.setAttribute(name, value);
        }
    }
    
    @Override
    public void dispose() {
        super.dispose();
        this.mainModuleTab = null;
    }
        
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -