EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.cip.runtime.dialogs]

COVERAGE SUMMARY FOR SOURCE FILE [FileSelectionWidget.java]

nameclass, %method, %block, %line, %
FileSelectionWidget.java0%   (0/2)0%   (0/12)0%   (0/311)0%   (0/73)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FileSelectionWidget0%   (0/1)0%   (0/9)0%   (0/282)0%   (0/64)
FileSelectionWidget (Composite, int): void 0%   (0/1)0%   (0/95)0%   (0/23)
access$0 (FileSelectionWidget): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
browseFileSystem (): boolean 0%   (0/1)0%   (0/76)0%   (0/14)
browseWorkspace (): boolean 0%   (0/1)0%   (0/62)0%   (0/13)
createButton (Composite, int): Button 0%   (0/1)0%   (0/28)0%   (0/6)
getText (): String 0%   (0/1)0%   (0/4)0%   (0/1)
setCaption (String): void 0%   (0/1)0%   (0/5)0%   (0/2)
setFileExtensions (String []): void 0%   (0/1)0%   (0/4)0%   (0/2)
setText (String): void 0%   (0/1)0%   (0/5)0%   (0/2)
     
class FileSelectionWidget$ButtonSelectionListener0%   (0/1)0%   (0/3)0%   (0/29)0%   (0/9)
FileSelectionWidget$ButtonSelectionListener (FileSelectionWidget, FileSelecti... 0%   (0/1)0%   (0/12)0%   (0/4)
widgetDefaultSelected (SelectionEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/16)0%   (0/4)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.cip.runtime.dialogs;
5 
6import java.io.File;
7 
8import org.eclipse.core.resources.IResource;
9import org.eclipse.core.resources.ResourcesPlugin;
10import org.eclipse.emf.common.util.URI;
11import org.eclipse.swt.SWT;
12import org.eclipse.swt.events.SelectionEvent;
13import org.eclipse.swt.events.SelectionListener;
14import org.eclipse.swt.layout.GridData;
15import org.eclipse.swt.layout.GridLayout;
16import org.eclipse.swt.widgets.Button;
17import org.eclipse.swt.widgets.Composite;
18import org.eclipse.swt.widgets.FileDialog;
19import org.eclipse.swt.widgets.Label;
20import org.eclipse.swt.widgets.Text;
21import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
22 
23class FileSelectionWidget extends Composite{
24 
25        private Label label;
26        private Text textfield;
27        private Button workspaceButton;
28        private Button filesystemButton;
29        
30        private String[] fileExtensions;
31 
32        public FileSelectionWidget(Composite parent, int style) {
33                super(parent, style);
34                GridLayout layout = new GridLayout(3,false);
35                setLayout(layout);
36                
37                label = new Label(this, SWT.LEFT);
38                label.setText("DUMMY");
39                GridData gd = new GridData();
40                gd.grabExcessHorizontalSpace = true;
41                gd.horizontalAlignment = SWT.FILL;
42                label.setLayoutData(gd);
43                
44                workspaceButton = createButton(this, WORKSPACE);
45                gd = new GridData();
46                workspaceButton.setLayoutData(gd);
47                
48                filesystemButton = createButton(this, FILESYSTEM);
49                gd = new GridData();
50                filesystemButton.setLayoutData(gd);
51                
52                textfield = new Text(this,SWT.BORDER);
53                gd = new GridData();
54                gd.horizontalSpan = layout.numColumns;
55                gd.grabExcessHorizontalSpace = true;
56                gd.horizontalAlignment = SWT.FILL;
57                gd.verticalAlignment = SWT.TOP;
58                textfield.setLayoutData(gd);
59                
60        }
61        
62        public void setCaption(String caption) {
63                label.setText(caption);
64        }
65        public void setFileExtensions(String[] fileExtensions) {
66                this.fileExtensions = fileExtensions;
67        }
68        
69        public void setText(String text) {
70                textfield.setText(text);
71        }
72        
73        public String getText() {
74                return textfield.getText();
75        }
76        
77        private final static int FILESYSTEM = 2;
78        private final static int WORKSPACE = 1;
79        
80        private Button createButton(Composite parent, int style) {
81                Button button = new Button(parent,SWT.PUSH);
82                if((style & WORKSPACE) == WORKSPACE) {
83                        button.setText("Browse &Workspace...");
84                }
85                else {
86                        button.setText("Browse &File System...");
87                        
88                }
89                button.addSelectionListener(new ButtonSelectionListener(this,style));
90                return button;
91        }
92 
93        public boolean browseWorkspace() {
94                /*ResourceSelectionDialog resourceSelectionDialog = new ResourceSelectionDialog(
95                  getShell(),
96                  ResourcesPlugin.getWorkspace().getRoot(),
97                  "File Selection");*/
98                
99                FilteredResourcesSelectionDialog resourceSelectionDialog = new FilteredResourcesSelectionDialog(getShell(), false, ResourcesPlugin.getWorkspace().getRoot(),IResource.DEPTH_INFINITE | IResource.FILE);
100                resourceSelectionDialog.open();
101                Object [] result = resourceSelectionDialog.getResult();
102                if (result != null)
103                {
104                  StringBuffer  text = new StringBuffer ();
105                  int length = result.length;
106                  for (int i = 0; i < length; ++i)
107                  {
108                    IResource resource = (IResource)result[i];
109                    //if (isValidWorkspaceResource(resource))
110                    {
111                      text.append(URI.createURI(URI.createPlatformResourceURI(resource.getFullPath().toString(),true).toString(), true));
112                      text.append(" ");
113                    }
114                  }
115                  textfield.setText(text.toString().trim());
116                  return true;
117                }
118                return false;
119        }
120 
121        private boolean browseFileSystem() {
122                FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI );
123                fileDialog.setFilterExtensions(fileExtensions);
124                
125                if (textfield.getText() != null)
126                {
127                  fileDialog.setFileName(textfield.getText());
128                }
129                
130                if (fileDialog.open() != null && fileDialog.getFileNames().length > 0)
131                {
132                  String [] fileNames = fileDialog.getFileNames();
133                  StringBuffer  text = new StringBuffer ();
134                  for (int i = 0; i < fileNames.length; ++i)
135                  {
136                    String  filePath = fileDialog.getFilterPath() + File.separator + fileNames[i];
137                    text.append(URI.createFileURI(filePath).toString());
138                    text.append(" ");
139                  }
140                  textfield.setText(text.toString().trim());
141                  
142                  return true;
143                }
144                return false;
145        }
146        
147        private class ButtonSelectionListener implements SelectionListener {
148                FileSelectionWidget widget;
149                int style;
150 
151                public ButtonSelectionListener(FileSelectionWidget fileSelectionWidget, int style) {
152                        widget = fileSelectionWidget;
153                        this.style = style;
154                }
155 
156                @Override
157                public void widgetDefaultSelected(SelectionEvent e) {
158                        
159                }
160 
161                @Override
162                public void widgetSelected(SelectionEvent e) {
163                        if((style & WORKSPACE) == WORKSPACE) {
164                                widget.browseWorkspace();
165                        }
166                        else {
167                                widget.browseFileSystem();
168                                
169                        }
170                }
171                
172        }
173}

[all classes][de.uka.ipd.sdq.cip.runtime.dialogs]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov