Conditions | 10 |
Total Lines | 144 |
Code Lines | 89 |
Lines | 0 |
Ratio | 0 % |
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.SparqlUpdateInsertStepDialog.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; |
||
67 | public String open() { |
||
68 | Shell parent = getParent(); |
||
69 | Display display = parent.getDisplay(); |
||
70 | |||
71 | shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); |
||
72 | props.setLook(shell); |
||
73 | setShellImage(shell, input); |
||
74 | |||
75 | ModifyListener lsMod = new ModifyListener() { |
||
76 | |||
77 | public void modifyText(ModifyEvent e) { |
||
78 | // TODO Auto-generated method stub |
||
79 | input.setChanged(); |
||
80 | } |
||
81 | }; |
||
82 | boolean changed = input.hasChanged(); |
||
83 | |||
84 | FormLayout formLayout = new FormLayout(); |
||
85 | formLayout.marginWidth = Const.FORM_MARGIN; |
||
86 | formLayout.marginHeight = Const.FORM_MARGIN; |
||
87 | |||
88 | shell.setLayout(formLayout); |
||
89 | |||
90 | shell.setText(this.dialogTitle); |
||
91 | |||
92 | int middle = props.getMiddlePct(); |
||
93 | int margin = Const.MARGIN; |
||
94 | |||
95 | // Adiciona um label e um input text no topo do dialog shell |
||
96 | wlStepname = new Label(shell, SWT.RIGHT); |
||
97 | wlStepname.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.StepNameField.Label")); |
||
98 | props.setLook(wlStepname); |
||
99 | |||
100 | fdlStepname = new FormData(); |
||
101 | fdlStepname.left = new FormAttachment(0, 0); |
||
102 | fdlStepname.right = new FormAttachment(middle, -margin); |
||
103 | fdlStepname.top = new FormAttachment(0, margin); |
||
104 | wlStepname.setLayoutData(fdlStepname); |
||
105 | |||
106 | wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); |
||
107 | wStepname.setText(stepname); |
||
108 | props.setLook(wStepname); |
||
109 | |||
110 | wStepname.addModifyListener(lsMod); |
||
111 | fdStepname = new FormData(); |
||
112 | fdStepname.left = new FormAttachment(middle, 0); |
||
113 | fdStepname.top = new FormAttachment(0, margin); |
||
114 | fdStepname.right = new FormAttachment(100, 0); |
||
115 | wStepname.setLayoutData(fdStepname); |
||
116 | Control lastControl = wStepname; |
||
117 | |||
118 | // Adiciona |
||
119 | Group wGroup1 = swthlp.appendGroup(shell, lastControl, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph")); |
||
120 | { |
||
121 | wRdfFieldName = swthlp.appendComboVarRow(wGroup1, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.NTriples"), lsMod); |
||
122 | wRdfFieldName.setItems(this.getFields(ValueMetaInterface.TYPE_STRING)); |
||
123 | wGraphUri = swthlp.appendTextVarRow(wGroup1, wRdfFieldName, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.URI"), lsMod); |
||
124 | wClearGraph = swthlp.appendCheckboxRow(wGroup1, wGraphUri, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Graph.Drop"), |
||
125 | new SelectionListener() { |
||
126 | |||
127 | public void widgetSelected(SelectionEvent arg0) { |
||
128 | input.setChanged(); |
||
129 | } |
||
130 | |||
131 | public void widgetDefaultSelected(SelectionEvent arg0) { |
||
132 | input.setChanged(); |
||
133 | } |
||
134 | }); |
||
135 | } |
||
136 | |||
137 | Group wGroup2 = swthlp.appendGroup(shell, wGroup1, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection")); |
||
138 | { |
||
139 | wEndpointUrl = swthlp.appendTextVarRow(wGroup2, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.Endpoint"), lsMod); |
||
140 | |||
141 | wUserName = swthlp.appendTextVarRow(wGroup2, wEndpointUrl, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.User"), lsMod); |
||
142 | |||
143 | wPassword = swthlp.appendTextVarRow(wGroup2, wUserName, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Connection.Password"), lsMod, true); |
||
144 | } |
||
145 | |||
146 | Group wGroup3 = swthlp.appendGroup(shell, wGroup2, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output")); |
||
147 | { |
||
148 | wStatusCode = swthlp.appendTextVarRow(wGroup3, null, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output.StatusCode"), lsMod); |
||
149 | wStatusMsg = swthlp.appendTextVarRow(wGroup3, wStatusCode, BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Output.StatusMessage"), lsMod); |
||
150 | } |
||
151 | |||
152 | lastControl = wGroup3; |
||
153 | |||
154 | // Some buttons |
||
155 | wOK = new Button(shell, SWT.PUSH); |
||
156 | wOK.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Btn.OK")); //$NON-NLS-1$ |
||
157 | wCancel = new Button(shell, SWT.PUSH); |
||
158 | wCancel.setText(BaseMessages.getString(PKG, "SparqlUpdateOutputStep.Btn.Cancel")); //$NON-NLS-1$ |
||
159 | |||
160 | setButtonPositions(new Button[] { wOK, wCancel }, margin, lastControl); |
||
161 | |||
162 | // Add listeners |
||
163 | lsCancel = new Listener() { |
||
164 | public void handleEvent(Event e) { |
||
165 | cancel(); |
||
166 | } |
||
167 | }; |
||
168 | lsOK = new Listener() { |
||
169 | public void handleEvent(Event e) { |
||
170 | ok(); |
||
171 | } |
||
172 | }; |
||
173 | |||
174 | wCancel.addListener(SWT.Selection, lsCancel); |
||
175 | wOK.addListener(SWT.Selection, lsOK); |
||
176 | |||
177 | lsDef = new SelectionAdapter() { |
||
178 | public void widgetDefaultSelected(SelectionEvent e) { |
||
179 | ok(); |
||
180 | } |
||
181 | }; |
||
182 | |||
183 | wStepname.addSelectionListener(lsDef); |
||
184 | wRdfFieldName.addSelectionListener(lsDef); |
||
185 | wGraphUri.addSelectionListener(lsDef); |
||
186 | wEndpointUrl.addSelectionListener(lsDef); |
||
187 | wUserName.addSelectionListener(lsDef); |
||
188 | wPassword.addSelectionListener(lsDef); |
||
189 | |||
190 | // Detect X or ALT-F4 or something that kills this window... |
||
191 | shell.addShellListener(new ShellAdapter() { |
||
192 | public void shellClosed(ShellEvent e) { |
||
193 | cancel(); |
||
194 | } |
||
195 | }); |
||
196 | |||
197 | // Populate the data of the controls |
||
198 | getData(); |
||
199 | |||
200 | // Set the shell size, based upon previous time... |
||
201 | setSize(); |
||
202 | |||
203 | input.setChanged(changed); |
||
204 | |||
205 | shell.open(); |
||
206 | while (!shell.isDisposed()) { |
||
207 | if (!display.readAndDispatch()) |
||
208 | display.sleep(); |
||
209 | } |
||
210 | return stepname; |
||
211 | } |
||
279 |