1 20 21 package org.apache.directory.ldapstudio.browser.common.actions; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.browser.core.ConnectionManager; 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 31 32 import org.eclipse.jface.resource.ImageDescriptor; 33 import org.eclipse.jface.viewers.StructuredSelection; 34 import org.eclipse.jface.viewers.Viewer; 35 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; 36 37 38 44 public class SelectAllAction extends BrowserAction 45 { 46 private Viewer viewer; 47 48 49 55 public SelectAllAction( Viewer viewer ) 56 { 57 this.viewer = viewer; 58 } 59 60 63 public String getText() 64 { 65 return "Select All"; 66 } 67 68 71 public ImageDescriptor getImageDescriptor() 72 { 73 return null; 74 } 75 76 79 public String getCommandId() 80 { 81 return IWorkbenchActionDefinitionIds.SELECT_ALL; 82 } 83 84 87 public boolean isEnabled() 88 { 89 return true; 90 } 91 92 95 public void run() 96 { 97 if ( getInput() != null && getInput() instanceof IEntry ) 98 { 99 List selectionList = new ArrayList (); 100 IAttribute[] attributes = ( ( IEntry ) getInput() ).getAttributes(); 101 if ( attributes != null ) 102 { 103 selectionList.addAll( Arrays.asList( attributes ) ); 104 for ( int i = 0; i < attributes.length; i++ ) 105 { 106 selectionList.addAll( Arrays.asList( attributes[i].getValues() ) ); 107 } 108 } 109 StructuredSelection selection = new StructuredSelection( selectionList ); 110 this.viewer.setSelection( selection ); 111 } 112 else if ( getInput() != null && getInput() instanceof ConnectionManager ) 113 { 114 StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) getInput() ) 115 .getConnections() ); 116 this.viewer.setSelection( selection ); 117 } 118 else if ( getSelectedConnections().length > 0 && viewer.getInput() instanceof ConnectionManager ) 119 { 120 StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) viewer.getInput() ) 121 .getConnections() ); 122 this.viewer.setSelection( selection ); 123 } 124 } 125 } 126 | Popular Tags |