|
From: Matthias K <mat...@us...> - 2006-04-19 21:36:06
|
Update of /cvsroot/jcommander/plugins/org.jcommander.ui.filepanel/src/org/jcommander/ui/filepanel/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8111/src/org/jcommander/ui/filepanel/actions Added Files: SimpleOpenURLAction.java Log Message: - First implementation of feature request 1473247: Simplified method to enter VFS URLs - with help link by context --- NEW FILE: SimpleOpenURLAction.java --- /** * */ package org.jcommander.ui.filepanel.actions; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileType; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; import org.jcommander.ui.filepanel.FilePanelManagerProvider; import org.jcommander.ui.logger.LoggerPlugin; import org.jcommander.vfsextensions.VfsManagerExtension; /** * @author MatthiasK * */ public class SimpleOpenURLAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; private Text protokollText; private Text hostText; private Text userNameText; private Text userPasswordText; private Text dirText; private String protokoll; private String host; private String userName; private String userPassword; private String dir; private Composite messageArea; private Text messageText; private boolean messageAreaVisible=false; private int messageHeight = 60; private class EnterTargetDialog extends TitleAreaDialog { protected EnterTargetDialog(Shell shell) { super(shell); } private void createMessageArea(){ if (messageAreaVisible) return; messageText = new Text(messageArea,SWT.MULTI|SWT.V_SCROLL|SWT.BORDER|SWT.READ_ONLY); GridData messageTextData = new GridData(); messageTextData.grabExcessHorizontalSpace=true; messageTextData.grabExcessVerticalSpace=true; messageTextData.horizontalAlignment=SWT.FILL; messageTextData.verticalAlignment=SWT.FILL; messageTextData.minimumHeight=60; messageText.setLayoutData(messageTextData); messageArea.layout(true); getShell().layout(true); getShell().setSize(getShell().getSize().x, getShell().getSize().y+messageHeight); messageArea.layout(true); getShell().layout(true); messageAreaVisible=true; //messageHeight=messageArea.getSize().y; } // @Override protected Control createDialogArea(Composite parent) { setTitle("Open VFS directory"); Composite dialogAreaSub = (Composite)super.createDialogArea(parent); Composite dialogArea = new Composite(dialogAreaSub, SWT.NONE); dialogArea.setLayout(new GridLayout(2,false)); dialogArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL,true,false)); Label protokolLabel = new Label(dialogArea, SWT.NONE); protokolLabel.setText("Protokoll"); protokollText = new Text(dialogArea, SWT.BORDER); protokollText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT,true,false)); Label hostLabel = new Label(dialogArea, SWT.NONE); hostLabel.setText("Host"); hostText = new Text(dialogArea, SWT.BORDER); hostText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT,true,false)); Label usernameLabel = new Label(dialogArea, SWT.NONE); usernameLabel.setText("Username"); userNameText = new Text(dialogArea, SWT.BORDER); userNameText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT,true,false)); Label userPasswordLabel = new Label(dialogArea, SWT.NONE); userPasswordLabel.setText("Password"); userPasswordText = new Text(dialogArea, SWT.BORDER); userPasswordText.setEchoChar('*'); userPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT,true,false)); Label dirLabel = new Label(dialogArea, SWT.NONE); dirLabel.setText("Directory"); dirText = new Text(dialogArea, SWT.BORDER); dirText.setText("/"); dirText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT,true,false)); messageArea=new Composite(dialogArea, SWT.NONE); GridData messageData=new GridData(); messageData.horizontalAlignment=SWT.FILL; messageData.verticalAlignment=SWT.FILL; messageData.horizontalSpan=2; messageArea.setLayoutData(messageData); GridLayout messageLayout = new GridLayout(); messageLayout.marginWidth=0; messageArea.setLayout(messageLayout); return dialogArea; } @Override protected void okPressed() { // if (messageText!=null) { // messageText.dispose(); // messageText=null; // shell.layout(true); // shell.setSize(shellSize.x, shellSize.y-messageHeight); // } // else { // createMessageArea(); // } protokoll=protokollText.getText(); userName=userNameText.getText(); userPassword=userPasswordText.getText(); host=hostText.getText(); dir=dirText.getText(); String userData=""; if (userName!="") userData=userName; if (userPassword!="") userData=userData+":"+userPassword; if (userData!="") userData=userData+"@"; String url=protokoll+"://"+userData+host+"/"+dir; if (performOk(url)) { super.okPressed(); } } private boolean performOk(final String url) { try { FileObject selectedDirectory = VfsManagerExtension.getInstance().resolveFile(url); if(selectedDirectory.getType() == FileType.FOLDER) { LoggerPlugin.rootLogger.debug("Changing dir to: "+ selectedDirectory.getName().getRootURI() + selectedDirectory.getName().getPath()); FilePanelManagerProvider.getTabManager() .getActiveTabMediator() .getFileTab() .getActiveFilePanel() .getPanelMediator() .changeDirectory(selectedDirectory); // TODO Why is this required?! FilePanelManagerProvider.getTabManager() .getActiveTabMediator() .getFileTab() .getActiveFilePanel() .getPanelMediator() .refresh(); //urlHistory.add(selectedDirectory); return true; } else { setMessage("Cannot change directory. Please specify a valid directory.",IMessageProvider.ERROR); return false; } } catch (FileSystemException ex) { String message; message=ex.getMessage(); Throwable effect= ex; Throwable cause=ex.getCause(); while (!(cause==null)&&!cause.equals(effect)) { message=message+": \n"+cause.getMessage(); effect=cause; cause=cause.getCause(); } setMessage("The directory could not be opened.", IMessageProvider.ERROR); setError(message); return false; } } private void setError(String Message){ createMessageArea(); messageText.setText(Message); } // @Override public void setMessage(String newMessage, int newType) { super.setMessage(newMessage, newType); } } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose() { } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ public void init(IWorkbenchWindow window) { this.window=window; } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { EnterTargetDialog dialog = new EnterTargetDialog(window.getShell()); dialog.setHelpAvailable(true); dialog.create(); PlatformUI.getWorkbench().getHelpSystem().setHelp(window.getShell(), "org.jcommander.ui.help.VFS"); dialog.open(); } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection selection) { } } |