| Conditions | 18 |
| Total Lines | 269 |
| Code Lines | 191 |
| Lines | 12 |
| Ratio | 4.46 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like br.ufrj.ppgi.greco.kettle.AnnotatorStepDialog.open() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | package br.ufrj.ppgi.greco.kettle; |
||
| 82 | public String open() { |
||
| 83 | |||
| 84 | Shell parent = getParent(); |
||
| 85 | Display display = parent.getDisplay(); |
||
| 86 | |||
| 87 | shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); |
||
| 88 | props.setLook(shell); |
||
| 89 | setShellImage(shell, input); |
||
| 90 | |||
| 91 | // ModifyListener padrao |
||
| 92 | ModifyListener lsMod = new ModifyListener() { |
||
| 93 | public void modifyText(ModifyEvent e) { |
||
| 94 | input.setChanged(); |
||
| 95 | } |
||
| 96 | }; |
||
| 97 | |||
| 98 | boolean changed = input.hasChanged(); |
||
| 99 | |||
| 100 | FormLayout formLayout = new FormLayout(); |
||
| 101 | formLayout.marginWidth = Const.FORM_MARGIN; |
||
| 102 | formLayout.marginHeight = Const.FORM_MARGIN; |
||
| 103 | |||
| 104 | shell.setLayout(formLayout); |
||
| 105 | |||
| 106 | shell.setText(dialogTitle); |
||
| 107 | |||
| 108 | int middle = props.getMiddlePct(); |
||
| 109 | int margin = Const.MARGIN; |
||
| 110 | |||
| 111 | // Adiciona um label e um input text no topo do dialog shell |
||
| 112 | wlStepname = new Label(shell, SWT.RIGHT); |
||
| 113 | wlStepname.setText(BaseMessages.getString(PKG, "AnnotatorStep.StepNameField.Label")); |
||
| 114 | props.setLook(wlStepname); |
||
| 115 | fdlStepname = new FormData(); |
||
| 116 | fdlStepname.left = new FormAttachment(0, 0); |
||
| 117 | fdlStepname.right = new FormAttachment(middle, -margin); |
||
| 118 | fdlStepname.top = new FormAttachment(0, margin); |
||
| 119 | wlStepname.setLayoutData(fdlStepname); |
||
| 120 | wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 121 | wStepname.setText(stepname); |
||
| 122 | props.setLook(wStepname); |
||
| 123 | wStepname.addModifyListener(lsMod); |
||
| 124 | fdStepname = new FormData(); |
||
| 125 | fdStepname.left = new FormAttachment(middle, 0); |
||
| 126 | fdStepname.top = new FormAttachment(0, margin); |
||
| 127 | fdStepname.right = new FormAttachment(100, 0); |
||
| 128 | wStepname.setLayoutData(fdStepname); |
||
| 129 | |||
| 130 | // Adiciona label e combo do campo sujeito |
||
| 131 | wlSubject = new Label(shell, SWT.RIGHT); |
||
| 132 | wlSubject.setText(BaseMessages.getString(PKG, "AnnotatorStep.SubjectField.Label")); |
||
| 133 | props.setLook(wlSubject); |
||
| 134 | fdlSubject = new FormData(); |
||
| 135 | fdlSubject.left = new FormAttachment(0, 0); |
||
| 136 | fdlSubject.top = new FormAttachment(wStepname, margin); |
||
| 137 | fdlSubject.right = new FormAttachment(middle, -margin); |
||
| 138 | wlSubject.setLayoutData(fdlSubject); |
||
| 139 | |||
| 140 | wcSubject = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 141 | props.setLook(wcSubject); |
||
| 142 | wcSubject.addModifyListener(lsMod); |
||
| 143 | fdcSubject = new FormData(); |
||
| 144 | fdcSubject.left = new FormAttachment(middle, 0); |
||
| 145 | fdcSubject.right = new FormAttachment(100, 0); |
||
| 146 | fdcSubject.top = new FormAttachment(wStepname, margin); |
||
| 147 | wcSubject.setLayoutData(fdcSubject); |
||
| 148 | wcSubject.addFocusListener(new FocusListener() { |
||
| 149 | public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
||
| 150 | } |
||
| 151 | |||
| 152 | public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
||
| 153 | Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
||
| 154 | shell.setCursor(busy); |
||
| 155 | BaseStepDialog.getFieldsFromPrevious(wcSubject, transMeta, stepMeta); |
||
| 156 | shell.setCursor(null); |
||
| 157 | busy.dispose(); |
||
| 158 | } |
||
| 159 | }); |
||
| 160 | |||
| 161 | // Adiciona label e combo do campo predicado |
||
| 162 | wlPredicate = new Label(shell, SWT.RIGHT); |
||
| 163 | wlPredicate.setText(BaseMessages.getString(PKG, "AnnotatorStep.PredicateField.Label")); |
||
| 164 | props.setLook(wlPredicate); |
||
| 165 | fdlPredicate = new FormData(); |
||
| 166 | fdlPredicate.left = new FormAttachment(0, 0); |
||
| 167 | fdlPredicate.top = new FormAttachment(wcSubject, margin); |
||
| 168 | fdlPredicate.right = new FormAttachment(middle, -margin); |
||
| 169 | wlPredicate.setLayoutData(fdlPredicate); |
||
| 170 | |||
| 171 | wcPredicate = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 172 | props.setLook(wcPredicate); |
||
| 173 | wcPredicate.addModifyListener(lsMod); |
||
| 174 | fdcPredicate = new FormData(); |
||
| 175 | fdcPredicate.left = new FormAttachment(middle, 0); |
||
| 176 | fdcPredicate.right = new FormAttachment(100, 0); |
||
| 177 | fdcPredicate.top = new FormAttachment(wcSubject, margin); |
||
| 178 | wcPredicate.setLayoutData(fdcPredicate); |
||
| 179 | wcPredicate.addFocusListener(new FocusListener() { |
||
| 180 | public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
||
| 181 | } |
||
| 182 | |||
| 183 | public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
||
| 184 | Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
||
| 185 | shell.setCursor(busy); |
||
| 186 | BaseStepDialog.getFieldsFromPrevious(wcPredicate, transMeta, stepMeta); |
||
| 187 | shell.setCursor(null); |
||
| 188 | busy.dispose(); |
||
| 189 | } |
||
| 190 | }); |
||
| 191 | |||
| 192 | // Adiciona label e combo do campo objeto |
||
| 193 | wlObject = new Label(shell, SWT.RIGHT); |
||
| 194 | wlObject.setText(BaseMessages.getString(PKG, "AnnotatorStep.ObjectField.Label")); |
||
| 195 | props.setLook(wlObject); |
||
| 196 | fdlObject = new FormData(); |
||
| 197 | fdlObject.left = new FormAttachment(0, 0); |
||
| 198 | fdlObject.top = new FormAttachment(wcPredicate, margin); |
||
| 199 | fdlObject.right = new FormAttachment(middle, -margin); |
||
| 200 | wlObject.setLayoutData(fdlObject); |
||
| 201 | |||
| 202 | wcObject = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 203 | props.setLook(wcObject); |
||
| 204 | wcObject.addModifyListener(lsMod); |
||
| 205 | fdcObject = new FormData(); |
||
| 206 | fdcObject.left = new FormAttachment(middle, 0); |
||
| 207 | fdcObject.right = new FormAttachment(100, 0); |
||
| 208 | fdcObject.top = new FormAttachment(wcPredicate, margin); |
||
| 209 | wcObject.setLayoutData(fdcObject); |
||
| 210 | wcObject.addFocusListener(new FocusListener() { |
||
| 211 | public void focusLost(org.eclipse.swt.events.FocusEvent e) { |
||
| 212 | } |
||
| 213 | |||
| 214 | public void focusGained(org.eclipse.swt.events.FocusEvent e) { |
||
| 215 | Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); |
||
| 216 | shell.setCursor(busy); |
||
| 217 | BaseStepDialog.getFieldsFromPrevious(wcObject, transMeta, stepMeta); |
||
| 218 | shell.setCursor(null); |
||
| 219 | busy.dispose(); |
||
| 220 | } |
||
| 221 | }); |
||
| 222 | |||
| 223 | // Adiciona label e text do campo saida |
||
| 224 | wlNTriple = new Label(shell, SWT.RIGHT); |
||
| 225 | wlNTriple.setText(BaseMessages.getString(PKG, "AnnotatorStep.NTripleField.Label")); //$NON-NLS-1$ |
||
| 226 | props.setLook(wlNTriple); |
||
| 227 | fdlNTriple = new FormData(); |
||
| 228 | fdlNTriple.left = new FormAttachment(0, 0); |
||
| 229 | fdlNTriple.right = new FormAttachment(middle, -margin); |
||
| 230 | fdlNTriple.top = new FormAttachment(wcObject, margin); |
||
| 231 | wlNTriple.setLayoutData(fdlNTriple); |
||
| 232 | |||
| 233 | wtNTriple = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 234 | wtNTriple.setText(""); //$NON-NLS-1$ |
||
| 235 | props.setLook(wtNTriple); |
||
| 236 | wtNTriple.addModifyListener(lsMod); |
||
| 237 | fdtNTriple = new FormData(); |
||
| 238 | fdtNTriple.left = new FormAttachment(middle, 0); |
||
| 239 | fdtNTriple.top = new FormAttachment(wcObject, margin); |
||
| 240 | fdtNTriple.right = new FormAttachment(100, 0); |
||
| 241 | wtNTriple.setLayoutData(fdtNTriple); |
||
| 242 | |||
| 243 | // Bottom buttons |
||
| 244 | wOK = new Button(shell, SWT.PUSH); |
||
| 245 | wOK.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.OK")); //$NON-NLS-1$ |
||
| 246 | wCancel = new Button(shell, SWT.PUSH); |
||
| 247 | wCancel.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Cancel")); //$NON-NLS-1$ |
||
| 248 | setButtonPositions(new Button[] { wOK, wCancel }, margin, wBrowse); |
||
| 249 | |||
| 250 | wlShape = new Label(shell, SWT.RIGHT); |
||
| 251 | wlShape.setText(BaseMessages.getString(PKG, "AnnotatorStep.MappingFile.Label")); |
||
| 252 | props.setLook(wlShape); |
||
| 253 | fdlShape = new FormData(); |
||
| 254 | fdlShape.left = new FormAttachment(0, 0); |
||
| 255 | fdlShape.top = new FormAttachment(wtNTriple, margin); |
||
| 256 | fdlShape.right = new FormAttachment(middle, -margin); |
||
| 257 | wlShape.setLayoutData(fdlShape); |
||
| 258 | |||
| 259 | // Botoes para busca de arquivo |
||
| 260 | wbBrowse = new Button(shell, SWT.PUSH | SWT.CENTER); |
||
| 261 | props.setLook(wbBrowse); |
||
| 262 | wbBrowse.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Browse")); |
||
| 263 | fdbBrowse = new FormData(); |
||
| 264 | fdbBrowse.right = new FormAttachment(100, 0); |
||
| 265 | fdbBrowse.top = new FormAttachment(wtNTriple, margin); |
||
| 266 | wbBrowse.setLayoutData(fdbBrowse); |
||
| 267 | |||
| 268 | wBrowse = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
| 269 | props.setLook(wBrowse); |
||
| 270 | wBrowse.addModifyListener(lsMod); |
||
| 271 | fdBrowse = new FormData(); |
||
| 272 | fdBrowse.left = new FormAttachment(middle, 0); |
||
| 273 | fdBrowse.right = new FormAttachment(wbBrowse, -margin); |
||
| 274 | fdBrowse.top = new FormAttachment(wtNTriple, margin); |
||
| 275 | wBrowse.setLayoutData(fdBrowse); |
||
| 276 | |||
| 277 | // Add listeners |
||
| 278 | lsCancel = new Listener() { |
||
| 279 | public void handleEvent(Event e) { |
||
| 280 | cancel(); |
||
| 281 | } |
||
| 282 | }; |
||
| 283 | lsOK = new Listener() { |
||
| 284 | public void handleEvent(Event e) { |
||
| 285 | ok(); |
||
| 286 | } |
||
| 287 | }; |
||
| 288 | |||
| 289 | wBrowse.addModifyListener(new ModifyListener() { |
||
| 290 | public void modifyText(ModifyEvent arg0) { |
||
| 291 | wBrowse.setToolTipText(transMeta.environmentSubstitute(wBrowse.getText())); |
||
| 292 | } |
||
| 293 | }); |
||
| 294 | |||
| 295 | wbBrowse.addSelectionListener(new SelectionAdapter() { |
||
| 296 | View Code Duplication | public void widgetSelected(SelectionEvent e) { |
|
|
|
|||
| 297 | FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
||
| 298 | dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" }); |
||
| 299 | if (wBrowse.getText() != null) { |
||
| 300 | dialog.setFileName(wBrowse.getText()); |
||
| 301 | } |
||
| 302 | |||
| 303 | dialog.setFilterNames(new String[] { "Text files", "All files" }); |
||
| 304 | |||
| 305 | if (dialog.open() != null) { |
||
| 306 | String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName(); |
||
| 307 | wBrowse.setText(str); |
||
| 308 | } |
||
| 309 | } |
||
| 310 | }); |
||
| 311 | |||
| 312 | wCancel.addListener(SWT.Selection, lsCancel); |
||
| 313 | wOK.addListener(SWT.Selection, lsOK); |
||
| 314 | |||
| 315 | // It closes the window affirmatively when the user press enter in one |
||
| 316 | // of the text input fields |
||
| 317 | lsDef = new SelectionAdapter() { |
||
| 318 | public void widgetDefaultSelected(SelectionEvent e) { |
||
| 319 | ok(); |
||
| 320 | } |
||
| 321 | }; |
||
| 322 | wStepname.addSelectionListener(lsDef); |
||
| 323 | |||
| 324 | // Detect X or ALT-F4 or something that kills this window... |
||
| 325 | shell.addShellListener(new ShellAdapter() { |
||
| 326 | public void shellClosed(ShellEvent e) { |
||
| 327 | cancel(); |
||
| 328 | } |
||
| 329 | }); |
||
| 330 | |||
| 331 | // Populate the data of the controls |
||
| 332 | getData(); |
||
| 333 | |||
| 334 | // Set the shell size, based upon previous time... |
||
| 335 | setSize(); |
||
| 336 | |||
| 337 | // Alarga um pouco mais a janela |
||
| 338 | Rectangle shellBounds = shell.getBounds(); |
||
| 339 | shellBounds.width += 5; |
||
| 340 | shellBounds.height += 5; |
||
| 341 | shell.setBounds(shellBounds); |
||
| 342 | |||
| 343 | input.setChanged(changed); |
||
| 344 | |||
| 345 | shell.open(); |
||
| 346 | while (!shell.isDisposed()) { |
||
| 347 | if (!display.readAndDispatch()) |
||
| 348 | display.sleep(); |
||
| 349 | } |
||
| 350 | return stepname; |
||
| 351 | } |
||
| 386 |