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

📄 abstractinterpretereditor.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        String executable = listControl.getSelection()[0];
                        InterpreterInfo info = (InterpreterInfo) interpreterManager.getInterpreterInfo(executable, new NullProgressMonitor());

                    
                        Widget widget = event.widget;
                        if (widget == addBtSystemFolder) {
                            DirectoryDialog dialog = new DirectoryDialog(getShell());
                            dialog.setFilterPath(lastDirectoryDialogPath);
                            String filePath = dialog.open();
                            if(filePath != null){
                                lastDirectoryDialogPath = filePath;
                                info.libs.add(filePath);
                                changed = true;
                            }
                            
                        } else if (widget == addBtSystemJar) {
                            FileDialog dialog = new FileDialog(getShell());
                            dialog.setFilterPath(lastFileDialogPath);
                            String filePath = dialog.open();
                            if(filePath != null){
                                lastFileDialogPath = filePath;
                                info.libs.add(filePath);
                                info.dllLibs.add(filePath);
                                changed = true;
                            }
                                
                        } else if (widget == removeBtSystemFolder) {
                            TreeItem[] selection = tree.getSelection();
                            for (int i = 0; i < selection.length; i++) {
                                TreeItem s = selection[i];
                                String text = s.getText();
                                info.libs.remove(text);
                                info.dllLibs.remove(text);
                                changed = true;
                            }
                        }
                        updateTree();
                    }
                }
            };
        }
        return selectionListenerSystem;
    }
    
    /**
     * 
     */
    protected void addOthers() {
        if (listControl.getSelectionCount() == 1) {
            String executable = listControl.getSelection()[0];
	        InterpreterInfo info = (InterpreterInfo) interpreterManager.getInterpreterInfo(executable, new NullProgressMonitor());
	        
	        InputDialog d = new InputDialog(this.getShell(), "Builtin to add", "Builtin to add", "", null);
	        
	        int retCode = d.open();
	        if (retCode == InputDialog.OK) {
		        info.addForcedLib(d.getValue());
                changed = true;
	        }

        }
        updateTree();
    }

    /**
     * 
     */
    protected void removeOthers() {
        if (listControl.getSelectionCount() == 1 && listBuiltins.getSelectionCount() == 1) {
            String executable = listControl.getSelection()[0];
            String builtin = listBuiltins.getSelection()[0];
            
	        InterpreterInfo info = (InterpreterInfo) interpreterManager.getInterpreterInfo(executable, new NullProgressMonitor());
	        info.removeForcedLib(builtin);
	        changed = true;
        }
        updateTree();
    }

    /**
     * Helper method to create a push button.
     * 
     * @param parent the parent control
     * @param key the resource name used to supply the button's label text
     * @param listenerToAdd 
     * @return Button
     */
    private Button createBt(Composite parent, String key, SelectionListener listenerToAdd) {
        Button button = new Button(parent, SWT.PUSH);
        button.setText(JFaceResources.getString(key));
        button.setFont(parent.getFont());
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
//        data.heightHint = convertVerticalDLUsToPixels(button, IDialogConstants.BUTTON_HEIGHT);
        int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
        data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
        button.setLayoutData(data);
        button.addSelectionListener(listenerToAdd);
        return button;
    }


    /**
     * @param listControl
     */
    private void updateTree() {
        if (listControl.getSelectionCount() == 1) {
            String s = listControl.getSelection()[0];
            fillPathItems(s);
        }else{
            fillPathItems(null);
            if (listControl.getItemCount() > 0){
                listControl.select(0);
                selectionChanged();
                String s = listControl.getSelection()[0];
                fillPathItems(s);
            }
        }
    }


    /**
     * @param s
     * 
     */
    private void fillPathItems(String executable) {
        tree.removeAll();
        listBuiltins.removeAll();
        
        if(executable != null){
	    	TreeItem item = new TreeItem(tree, SWT.NONE);
	    	item.setText("System libs");
	    	item.setImage(imageSystemLibRoot);

	    	InterpreterInfo info = (InterpreterInfo) interpreterManager.getInterpreterInfo(executable, new NullProgressMonitor());
	    	
	    	for (Iterator<String> iter = info.libs.iterator(); iter.hasNext();) {
	            TreeItem subItem = new TreeItem(item, SWT.NONE);
	            subItem.setText(iter.next());
	            subItem.setImage(imageSystemLib);
	        }
	    	item.setExpanded(true);
	    	
	    	//ok, now set the dlls
	    	item = new TreeItem(tree, SWT.NONE);
	    	item.setText("Compiled libs found in PYTHONPATH (dlls)");
	    	item.setImage(imageSystemLibRoot);

	    	for (Iterator<String> iter = info.dllLibs.iterator(); iter.hasNext();) {
	            TreeItem subItem = new TreeItem(item, SWT.NONE);
	            subItem.setText(iter.next());
	            subItem.setImage(imageSystemLib);
	        }
	    	item.setExpanded(false);
	    	
	    	
	    	//set the forced builtins
	    	for (Iterator<String> iter = info.forcedLibsIterator(); iter.hasNext();) {
	    	    listBuiltins.add((String) iter.next());
            }
        }
    }


    /**
     * @return a string with the extensions that are accepted for the interpreter
     */
    public abstract String[] getInterpreterFilterExtensions();
    
    /** Overriden
     */
    protected String getNewInputObject() {
    	CharArrayWriter charWriter = new CharArrayWriter();
    	PrintWriter logger = new PrintWriter(charWriter);
    	logger.println("Information about process of adding new interpreter:");
        try {
        	
			FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

			String[] filterExtensions = getInterpreterFilterExtensions();
			if (filterExtensions != null) {
				dialog.setFilterExtensions(filterExtensions);
			}

			if (lastPath != null) {
				if (new File(lastPath).exists())
					dialog.setFilterPath(lastPath);
			}

			logger.println("- Opening dialog to request executable (or jar).");
			String file = dialog.open();
			if (file != null) {
				logger.println("- Chosen interpreter file:'"+file);
				file = file.trim();
				if (file.length() == 0){
					logger.println("- When trimmed, the chosen file was empty (returning null).");
					return null;
				}
				lastPath = file;
			}else{
				logger.println("- The file chosen was null (returning null).");
				return null;
			}
			
			if (file != null) {
				//ok, now that we got the file, let's see if it is valid and get the library info.
				logger.println("- Ok, file is non-null. Getting info on:"+file);
				ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(this.getShell());
				monitorDialog.setBlockOnOpen(false);
				Operation operation = new Operation(file, logger);
				monitorDialog.run(true, false, operation);

				if (operation.e != null) {
					logger.println("- Some error happened while getting info on the interpreter:");
					operation.e.printStackTrace(logger);

					if(operation.e instanceof SimpleJythonRunner.JavaNotConfiguredException){
                        SimpleJythonRunner.JavaNotConfiguredException javaNotConfiguredException = (SimpleJythonRunner.JavaNotConfiguredException) operation.e;
                        
                        ErrorDialog.openError(this.getShell(), "Error getting info on interpreter", 
                                javaNotConfiguredException.getMessage(), 
                                PydevPlugin.makeStatus(IStatus.ERROR, "Java vm not configured.\n", javaNotConfiguredException));
                        
					}else if(operation.e instanceof JDTNotAvailableException){
					    JDTNotAvailableException noJdtException = (JDTNotAvailableException) operation.e;
                        ErrorDialog.openError(this.getShell(), "Error getting info on interpreter", 
                                noJdtException.getMessage(), 
					            PydevPlugin.makeStatus(IStatus.ERROR, "JDT not available.\n", noJdtException));
					    
					}else{
                        String errorMsg = "Some error happened while getting info on the interpreter.\n\n" +
                                    "Common reasons include:\n\n" +
                                    "- Specifying an invalid interpreter" +
                                    "(usually a link to the actual interpreter on Mac or Linux)\n" +
                                    "- Having spaces in your Eclipse installation path.";
                        //show the user a message (so that it does not fail silently)...
                        ErrorDialog.openError(this.getShell(), "Error getting info on interpreter", 
                                errorMsg, 
                                PydevPlugin.makeStatus(IStatus.ERROR, "Check your error log for more details.\n\n" +
                                    "More info can also be found at the bug report: http://sourceforge.net/tracker/index.php?func=detail&aid=1523582&group_id=85796&atid=577329", 
                                operation.e));
					}
                    
					throw operation.e;
				}

				logger.println("- Success getting the info. Result:"+operation.result);
				return operation.result;
			}
			
        } catch (Exception e) {
            PydevPlugin.log(e);
            return null;
        } finally {
        	PydevPlugin.logInfo(charWriter.toString());
        }
        
        return null;
    }

    @Override
    protected void doStore() {
        String s = createList(list.getItems());
        if (s != null){
        	interpreterManager.setPersistedString(s);
        }
    }
    
    @Override
    protected void doLoad() {
        if (list != null) {
        	String s = interpreterManager.getPersistedString();
            String[] array = parseString(s);
            for (int i = 0; i < array.length; i++) {
                list.add(array[i]);
            }
        }
        updateTree();
    }

    public String getPreferenceName(){
    	throw new RuntimeException("The preferences should be stored/gotten from the IInterpreterManager, and not directly.");
    }
    
    /** Overriden
     */
    @Override
    protected String createList(String[] executables) {
        return interpreterManager.getStringToPersist(executables);
    }
    
    /** Overriden
     */
    @Override
    protected String[] parseString(String stringList) {
        return interpreterManager.getInterpretersFromPersistedString(stringList);
    }

    private static class OperationMonitor extends ProgressMonitorWrapper{

		private PrintWriter logger;

		protected OperationMonitor(IProgressMonitor monitor, PrintWriter logger) {
			super(monitor);
			this.logger = logger;
		}
    	
		@Override
		public void beginTask(String name, int totalWork) {
			super.beginTask(name, totalWork);
			logger.print("- Beggining task:");
			logger.print(name);
			logger.print(" totalWork:");
			logger.println(totalWork);
		}
		
		@Override
		public void setTaskName(String name) {
			super.setTaskName(name);
			logger.print("- Setting task name:");
			logger.println(name);
		}
		
		@Override
		public void subTask(String name) {
			super.subTask(name);
			logger.print("- Sub Task:");
			logger.println(name);
		}
    }
    private class Operation implements IRunnableWithProgress{

        public String result;
        public String file;
        public Exception e;
		private PrintWriter logger;
        
        /**
         * @param file2
         * @param logger 
         */
        public Operation(String file2, PrintWriter logger) {
            this.file = file2;
            this.logger = logger;
        }

        /**
         * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
         */
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
        	monitor = new OperationMonitor(monitor, logger);
            monitor.beginTask("Getting libs", 100);
            try {
                result = interpreterManager.addInterpreter(file, monitor);
            } catch (Exception e) {
            	logger.println("Exception detected: "+e.getMessage());
                this.e = e;
            }
            monitor.done();
        }
        
    }
    
    /**
     * @see org.python.copiedfromeclipsesrc.PythonListEditor#doLoadDefault()
     */
    protected void doLoadDefault() {
        super.doLoadDefault();
        updateTree();
    }

    public boolean hasChanged() {
        return changed;
    }

}

⌨️ 快捷键说明

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