1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.commands.AbstractHandler; 18 import org.eclipse.core.commands.ExecutionEvent; 19 import org.eclipse.core.commands.ExecutionException; 20 import org.eclipse.core.commands.IHandler; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.core.runtime.NullProgressMonitor; 24 import org.eclipse.core.runtime.OperationCanceledException; 25 import org.eclipse.jdt.core.IType; 26 import org.eclipse.jdt.core.JavaCore; 27 import org.eclipse.jdt.core.JavaModelException; 28 import org.eclipse.jdt.core.search.IJavaSearchConstants; 29 import org.eclipse.jdt.core.search.IJavaSearchScope; 30 import org.eclipse.jdt.core.search.SearchEngine; 31 import org.eclipse.jdt.core.search.SearchMatch; 32 import org.eclipse.jdt.core.search.SearchParticipant; 33 import org.eclipse.jdt.core.search.SearchPattern; 34 import org.eclipse.jdt.core.search.SearchRequestor; 35 import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaLogicalStructure; 36 import org.eclipse.jdt.internal.debug.ui.contentassist.DynamicTypeContext; 37 import org.eclipse.jdt.internal.debug.ui.contentassist.JavaDebugContentAssistProcessor; 38 import org.eclipse.jdt.internal.debug.ui.contentassist.DynamicTypeContext.ITypeProvider; 39 import org.eclipse.jdt.internal.debug.ui.display.DisplayViewerConfiguration; 40 import org.eclipse.jdt.ui.IJavaElementSearchConstants; 41 import org.eclipse.jdt.ui.JavaUI; 42 import org.eclipse.jdt.ui.text.IJavaPartitions; 43 import org.eclipse.jdt.ui.text.JavaTextTools; 44 import org.eclipse.jface.dialogs.IDialogConstants; 45 import org.eclipse.jface.dialogs.StatusDialog; 46 import org.eclipse.jface.text.Document; 47 import org.eclipse.jface.text.DocumentEvent; 48 import org.eclipse.jface.text.IDocumentListener; 49 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 50 import org.eclipse.jface.text.source.ISourceViewer; 51 import org.eclipse.jface.viewers.ISelectionChangedListener; 52 import org.eclipse.jface.viewers.IStructuredContentProvider; 53 import org.eclipse.jface.viewers.IStructuredSelection; 54 import org.eclipse.jface.viewers.LabelProvider; 55 import org.eclipse.jface.viewers.SelectionChangedEvent; 56 import org.eclipse.jface.viewers.StructuredSelection; 57 import org.eclipse.jface.viewers.TableViewer; 58 import org.eclipse.jface.viewers.Viewer; 59 import org.eclipse.swt.SWT; 60 import org.eclipse.swt.layout.GridData; 61 import org.eclipse.swt.layout.GridLayout; 62 import org.eclipse.swt.widgets.Button; 63 import org.eclipse.swt.widgets.Composite; 64 import org.eclipse.swt.widgets.Control; 65 import org.eclipse.swt.widgets.Event; 66 import org.eclipse.swt.widgets.Group; 67 import org.eclipse.swt.widgets.Listener; 68 import org.eclipse.swt.widgets.Shell; 69 import org.eclipse.swt.widgets.Table; 70 import org.eclipse.swt.widgets.Text; 71 import org.eclipse.swt.widgets.Widget; 72 import org.eclipse.ui.IWorkbench; 73 import org.eclipse.ui.PlatformUI; 74 import org.eclipse.ui.dialogs.SelectionDialog; 75 import org.eclipse.ui.handlers.IHandlerActivation; 76 import org.eclipse.ui.handlers.IHandlerService; 77 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 78 79 import com.ibm.icu.text.MessageFormat; 80 81 84 public class EditLogicalStructureDialog extends StatusDialog implements Listener, ISelectionChangedListener, IDocumentListener, ITypeProvider { 85 86 public class AttributesContentProvider implements IStructuredContentProvider { 87 88 private final List fVariables; 89 90 public AttributesContentProvider(String [][] variables) { 91 fVariables= new ArrayList (); 92 for (int i= 0; i < variables.length; i++) { 93 String [] variable= new String [2]; 94 variable[0]= variables[i][0]; 95 variable[1]= variables[i][1]; 96 fVariables.add(variable); 97 } 98 } 99 100 103 public void dispose() { 104 } 105 106 109 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 110 } 111 112 115 public Object [] getElements(Object inputElement) { 116 return getElements(); 117 } 118 119 122 public String [][] getElements() { 123 return (String [][])fVariables.toArray(new String [fVariables.size()][]); 124 } 125 126 129 public void add(String [] newAttribute) { 130 fVariables.add(newAttribute); 131 } 132 133 136 public void remove(List list) { 137 fVariables.removeAll(list); 138 } 139 140 143 public void up(List list) { 144 for (Iterator iter= list.iterator(); iter.hasNext();) { 145 String [] variable= (String []) iter.next(); 146 int index= fVariables.indexOf(variable); 147 fVariables.remove(variable); 148 fVariables.add(index - 1, variable); 149 } 150 } 151 152 155 public void down(List list) { 156 for (Iterator iter= list.iterator(); iter.hasNext();) { 157 String [] variable= (String []) iter.next(); 158 int index= fVariables.indexOf(variable); 159 fVariables.remove(variable); 160 fVariables.add(index + 1, variable); 161 } 162 } 163 164 } 165 166 public class AttributesLabelProvider extends LabelProvider { 167 public String getText(Object element) { 168 return ((String [])element)[0]; 169 } 170 } 171 172 private final JavaLogicalStructure fLogicalStructure; 173 private Text fQualifiedTypeNameText; 174 private Text fDescriptionText; 175 private TableViewer fAttributeListViewer; 176 private Button fSubTypeButton; 177 private Button fValueButton; 178 private Button fVariablesButton; 179 private Button fAttributeUpButton; 180 private Button fAttributeDownButton; 181 private JDISourceViewer fSnippetViewer; 182 private Document fSnippetDocument; 183 private Button fBrowseTypeButton; 184 private Button fAttributeAddButton; 185 private Button fAttributeRemoveButton; 186 private Text fAttributeNameText; 187 private Composite fAttributesContainer; 188 private Group fCodeGroup; 189 private Composite fParentComposite; 190 private AttributesContentProvider fAttributesContentProvider; 191 private String fValueTmp; 192 private IStructuredSelection fCurrentAttributeSelection; 193 private IType fType; 194 private boolean fTypeSearched= false; 195 private DisplayViewerConfiguration fViewerConfiguration; 196 private IHandlerActivation fHandlerActivation; 197 198 public EditLogicalStructureDialog(Shell parentShell, JavaLogicalStructure logicalStructure) { 199 super(parentShell); 200 setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE); 201 if (logicalStructure.getQualifiedTypeName().length() == 0) { 202 setTitle(DebugUIMessages.EditLogicalStructureDialog_32); 203 } else { 204 setTitle(DebugUIMessages.EditLogicalStructureDialog_31); 205 } 206 fLogicalStructure= logicalStructure; 207 } 208 209 212 protected Control createDialogArea(Composite parent) { 213 IWorkbench workbench = PlatformUI.getWorkbench(); 214 workbench.getHelpSystem().setHelp( 215 parent, 216 IJavaDebugHelpContextIds.EDIT_LOGICAL_STRUCTURE_DIALOG); 217 fParentComposite= parent; 218 219 IHandler handler = new AbstractHandler() { 220 public Object execute(ExecutionEvent event) throws ExecutionException { 221 if(fSnippetViewer.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS) && fSnippetViewer.getControl().isFocusControl()){ 222 findCorrespondingType(); 223 fSnippetViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); 224 } 225 return null; 226 } 227 }; 228 229 IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class); 230 fHandlerActivation = handlerService.activateHandler(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler); 231 232 Composite container = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_BOTH); 233 234 Composite typeNameDescriptionContainer = SWTFactory.createComposite(container, container.getFont(), 2, 1, GridData.FILL_HORIZONTAL); 235 236 SWTFactory.createLabel(typeNameDescriptionContainer, DebugUIMessages.EditLogicalStructureDialog_0, 2); 237 238 fQualifiedTypeNameText = SWTFactory.createSingleText(typeNameDescriptionContainer, 1); 239 fQualifiedTypeNameText.addListener(SWT.Modify, this); 240 241 fBrowseTypeButton = SWTFactory.createPushButton(typeNameDescriptionContainer, DebugUIMessages.EditLogicalStructureDialog_1, DebugUIMessages.EditLogicalStructureDialog_25, null); 242 243 fBrowseTypeButton.addListener(SWT.Selection, this); 244 245 SWTFactory.createLabel(typeNameDescriptionContainer, DebugUIMessages.EditLogicalStructureDialog_2, 2); 246 247 fDescriptionText = SWTFactory.createSingleText(typeNameDescriptionContainer, 2); 248 fDescriptionText.addListener(SWT.Modify, this); 249 250 fSubTypeButton = SWTFactory.createCheckButton(typeNameDescriptionContainer, DebugUIMessages.EditLogicalStructureDialog_3, null, false, 1); 251 fSubTypeButton.setToolTipText(DebugUIMessages.EditLogicalStructureDialog_26); 252 253 Group radioContainer= SWTFactory.createGroup(container, DebugUIMessages.EditLogicalStructureDialog_33, 1, 1, GridData.FILL_HORIZONTAL); 254 255 fValueButton = SWTFactory.createRadioButton(radioContainer, DebugUIMessages.EditLogicalStructureDialog_4); 256 fValueButton.addListener(SWT.Selection, this); 257 258 fVariablesButton = SWTFactory.createRadioButton(radioContainer, DebugUIMessages.EditLogicalStructureDialog_5); 259 260 fAttributesContainer = SWTFactory.createComposite(container, container.getFont(), 2, 1, GridData.FILL_HORIZONTAL); 261 262 boolean isValue = fLogicalStructure.getValue() != null; 263 if (!isValue) { 264 createAttributeListWidgets(); 266 } 267 268 fCodeGroup = SWTFactory.createGroup(container, "", 1, 1, GridData.FILL_BOTH); createCodeGroupWidgets(isValue); 270 271 applyDialogFont(container); 272 273 initializeData(); 274 275 return container; 276 } 277 278 281 private void createCodeGroupWidgets(boolean isValue) { 282 if (isValue) { 283 fCodeGroup.setText(DebugUIMessages.EditLogicalStructureDialog_9); 284 } else { 285 fCodeGroup.setText(DebugUIMessages.EditLogicalStructureDialog_7); 286 287 Composite attributeNameContainer = SWTFactory.createComposite(fCodeGroup, fCodeGroup.getFont(), 2, 1, GridData.FILL_HORIZONTAL); 288 ((GridLayout)attributeNameContainer.getLayout()).marginWidth = 0; 289 290 SWTFactory.createLabel(attributeNameContainer, DebugUIMessages.EditLogicalStructureDialog_8, 1); 291 292 fAttributeNameText = SWTFactory.createSingleText(attributeNameContainer, 1); 293 fAttributeNameText.addListener(SWT.Modify, this); 294 295 SWTFactory.createLabel(fCodeGroup, DebugUIMessages.EditLogicalStructureDialog_9, 1); 296 } 297 298 fSnippetViewer= new JDISourceViewer(fCodeGroup, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL ); 300 fSnippetViewer.setInput(this); 301 302 JavaTextTools tools= JDIDebugUIPlugin.getDefault().getJavaTextTools(); 303 if (fSnippetDocument == null) { 304 fSnippetDocument= new Document(); 305 fSnippetDocument.addDocumentListener(this); 306 } 307 tools.setupJavaDocumentPartitioner(fSnippetDocument, IJavaPartitions.JAVA_PARTITIONING); 308 if (fViewerConfiguration == null) { 309 fViewerConfiguration= new DisplayViewerConfiguration() { 310 public IContentAssistProcessor getContentAssistantProcessor() { 311 return new JavaDebugContentAssistProcessor(new DynamicTypeContext(EditLogicalStructureDialog.this)); 312 } 313 }; 314 } 315 fSnippetViewer.configure(fViewerConfiguration); 316 fSnippetViewer.setEditable(true); 317 fSnippetViewer.setDocument(fSnippetDocument); 318 319 Control control= fSnippetViewer.getControl(); 320 GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true); 321 gd.heightHint= convertHeightInCharsToPixels(isValue ? 20 : 10); 322 gd.widthHint= convertWidthInCharsToPixels(80); 323 control.setLayoutData(gd); 324 } 325 326 329 private void createAttributeListWidgets() { 330 fAttributeListViewer = new TableViewer(fAttributesContainer, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 331 Table table = (Table)fAttributeListViewer.getControl(); 332 GridData gd= new GridData(SWT.FILL, SWT.FILL, true, false); 333 gd.heightHint= convertHeightInCharsToPixels(5); 334 gd.widthHint= convertWidthInCharsToPixels(10); 335 table.setLayoutData(gd); 336 table.setFont(fAttributesContainer.getFont()); 337 if (fAttributesContentProvider == null) { 338 fAttributesContentProvider= new AttributesContentProvider(fLogicalStructure.getVariables()); 339 } 340 fAttributeListViewer.setContentProvider(fAttributesContentProvider); 341 fAttributeListViewer.setLabelProvider(new AttributesLabelProvider()); 342 fAttributeListViewer.setInput(this); 343 fAttributeListViewer.addSelectionChangedListener(this); 344 345 Composite attributeListButtonsCotnainer = SWTFactory.createComposite(fAttributesContainer, fAttributesContainer.getFont(), 1, 1, SWT.NONE); 346 347 fAttributeAddButton = SWTFactory.createPushButton(attributeListButtonsCotnainer, DebugUIMessages.EditLogicalStructureDialog_10, DebugUIMessages.EditLogicalStructureDialog_27, null); 348 fAttributeAddButton.addListener(SWT.Selection, this); 349 350 fAttributeRemoveButton = SWTFactory.createPushButton(attributeListButtonsCotnainer, DebugUIMessages.EditLogicalStructureDialog_11, DebugUIMessages.EditLogicalStructureDialog_28, null); 351 fAttributeRemoveButton.addListener(SWT.Selection, this); 352 353 fAttributeUpButton = SWTFactory.createPushButton(attributeListButtonsCotnainer, DebugUIMessages.EditLogicalStructureDialog_12, DebugUIMessages.EditLogicalStructureDialog_29, null); 354 fAttributeUpButton.addListener(SWT.Selection, this); 355 356 fAttributeDownButton = SWTFactory.createPushButton(attributeListButtonsCotnainer, DebugUIMessages.EditLogicalStructureDialog_13, DebugUIMessages.EditLogicalStructureDialog_30, null); 357 fAttributeDownButton.addListener(SWT.Selection, this); 358 } 359 360 private void initializeData() { 361 fQualifiedTypeNameText.setText(fLogicalStructure.getQualifiedTypeName()); 362 fDescriptionText.setText(fLogicalStructure.getDescription()); 363 fSubTypeButton.setSelection(fLogicalStructure.isSubtypes()); 364 fValueTmp= fLogicalStructure.getValue(); 365 if (fValueTmp == null) { 366 fValueTmp= ""; fVariablesButton.setSelection(true); 368 setAttributesData(false); 369 } else { 370 fValueButton.setSelection(true); 371 setAttributesData(true); 372 } 373 checkValues(); 374 } 375 376 379 public void handleEvent(Event event) { 380 Widget source= event.widget; 381 switch (event.type) { 382 case SWT.Selection: 383 if (source == fValueButton) { 384 toggleAttributesWidgets(fValueButton.getSelection()); 385 checkValues(); 386 } else if (source == fBrowseTypeButton) { 387 selectType(); 388 } else if (source == fAttributeAddButton) { 389 addAttribute(); 390 } else if (source == fAttributeRemoveButton) { 391 removeAttribute(); 392 } else if (source == fAttributeUpButton) { 393 attributeUp(); 394 } else if (source == fAttributeDownButton) { 395 attributeDown(); 396 } 397 break; 398 case SWT.Modify: 399 if (source == fAttributeNameText) { 400 saveNewAttributeName(); 401 checkValues(); 402 } else if (source == fQualifiedTypeNameText) { 403 checkValues(); 404 fTypeSearched= false; 405 } else if (source == fDescriptionText) { 406 checkValues(); 407 } 408 break; 409 } 410 } 411 412 private void addAttribute() { 414 String [] newAttribute= new String [] {DebugUIMessages.EditLogicalStructureDialog_14, DebugUIMessages.EditLogicalStructureDialog_15}; fAttributesContentProvider.add(newAttribute); 416 fAttributeListViewer.refresh(); 417 fAttributeListViewer.setSelection(new StructuredSelection((Object )newAttribute)); 418 } 419 420 private void removeAttribute() { 422 IStructuredSelection selection= (IStructuredSelection)fAttributeListViewer.getSelection(); 423 if (selection.size() > 0) { 424 List selectedElements= selection.toList(); 425 Object [] elements= fAttributesContentProvider.getElements(); 426 Object newSelectedElement= null; 427 for (int i= 0; i < elements.length; i++) { 428 if (!selectedElements.contains(elements[i])) { 429 newSelectedElement= elements[i]; 430 } else { 431 break; 432 } 433 } 434 fAttributesContentProvider.remove(selectedElements); 435 fAttributeListViewer.refresh(); 436 if (newSelectedElement == null) { 437 Object [] newElements= fAttributesContentProvider.getElements(); 438 if (newElements.length > 0) { 439 fAttributeListViewer.setSelection(new StructuredSelection(newElements[0])); 440 } 441 } else { 442 fAttributeListViewer.setSelection(new StructuredSelection(newSelectedElement)); 443 } 444 } 445 } 446 447 private void attributeUp() { 449 IStructuredSelection selection= (IStructuredSelection)fAttributeListViewer.getSelection(); 450 if (selection.size() > 0) { 451 fAttributesContentProvider.up(selection.toList()); 452 fAttributeListViewer.refresh(); 453 fAttributeListViewer.setSelection(selection); 454 } 455 } 456 457 private void attributeDown() { 459 IStructuredSelection selection= (IStructuredSelection)fAttributeListViewer.getSelection(); 460 if (selection.size() > 0) { 461 fAttributesContentProvider.down(selection.toList()); 462 fAttributeListViewer.refresh(); 463 fAttributeListViewer.setSelection(selection); 464 } 465 } 466 467 private void saveNewAttributeName() { 469 if (fCurrentAttributeSelection.size() == 1) { 470 String [] variable= (String [])fCurrentAttributeSelection.getFirstElement(); 471 variable[0]= fAttributeNameText.getText(); 472 fAttributeListViewer.refresh(variable); 473 } 474 } 475 476 480 private void toggleAttributesWidgets(boolean isValue) { 481 if (!isValue) { 482 fValueTmp= fSnippetDocument.get(); 484 createAttributeListWidgets(); 485 } else if (isValue) { 486 saveAttributeValue(); 488 Control[] children= fAttributesContainer.getChildren(); 489 for (int i= 0; i < children.length; i++) { 490 children[i].dispose(); 491 } 492 } 493 494 Control[] children= fCodeGroup.getChildren(); 496 for (int i = 0; i < children.length; i++) { 497 children[i].dispose(); 498 } 499 fSnippetViewer.dispose(); 500 createCodeGroupWidgets(isValue); 501 setAttributesData(isValue); 502 fParentComposite.layout(true, true); 503 } 504 505 508 private void setAttributesData(boolean isValue) { 509 if (isValue) { 510 fSnippetDocument.set(fValueTmp); 511 } else { 512 Object [] elements= fAttributesContentProvider.getElements(null); 513 fCurrentAttributeSelection= new StructuredSelection(); 514 if (elements.length > 0) { 515 IStructuredSelection newSelection= new StructuredSelection(elements[0]); 516 fAttributeListViewer.setSelection(newSelection); 517 } else { 518 fAttributeListViewer.setSelection(fCurrentAttributeSelection); 519 } 520 521 } 522 } 523 524 527 private void setNameValueToSelection() { 528 if (fCurrentAttributeSelection.size() == 1) { 529 String [] variable= (String []) fCurrentAttributeSelection.getFirstElement(); 530 fAttributeNameText.setText(variable[0]); 531 fSnippetDocument.set(variable[1]); 532 fAttributeNameText.setEnabled(true); 533 fSnippetViewer.setEditable(true); 534 fAttributeNameText.setSelection(0, variable[0].length()); 535 fAttributeNameText.setFocus(); 536 } else { 537 fAttributeNameText.setEnabled(false); 538 fSnippetViewer.setEditable(false); 539 fAttributeNameText.setText(""); fSnippetDocument.set(""); } 542 } 543 544 private void saveAttributeValue() { 546 if (fCurrentAttributeSelection.size() == 1) { 547 ((String [])fCurrentAttributeSelection.getFirstElement())[1]= fSnippetDocument.get(); 548 } 549 } 550 551 554 public void selectionChanged(SelectionChangedEvent event) { 555 saveAttributeValue(); 556 fCurrentAttributeSelection= (IStructuredSelection) event.getSelection(); 557 setNameValueToSelection(); 558 updateAttributeListButtons(); 559 } 560 561 564 private void updateAttributeListButtons() { 565 int selectionSize= fCurrentAttributeSelection.size(); 566 if (selectionSize > 0) { 567 fAttributeRemoveButton.setEnabled(true); 568 Object [] elements= fAttributesContentProvider.getElements(); 569 fAttributeUpButton.setEnabled(fCurrentAttributeSelection.getFirstElement() != elements[0]); 570 fAttributeDownButton.setEnabled(fCurrentAttributeSelection.toArray()[selectionSize - 1] != elements[elements.length - 1]); 571 } else { 572 fAttributeRemoveButton.setEnabled(false); 573 fAttributeUpButton.setEnabled(false); 574 fAttributeDownButton.setEnabled(false); 575 } 576 } 577 578 581 public void checkValues() { 582 StatusInfo status= new StatusInfo(); 583 if (fQualifiedTypeNameText.getText().trim().length() == 0) { 584 status.setError(DebugUIMessages.EditLogicalStructureDialog_16); 585 } else if (fDescriptionText.getText().trim().length() == 0) { 586 status.setError(DebugUIMessages.EditLogicalStructureDialog_17); 587 } else if (fValueButton.getSelection() && fSnippetDocument.get().length() == 0) { 588 status.setError(DebugUIMessages.EditLogicalStructureDialog_18); 589 } else if (fVariablesButton.getSelection()) { 590 Object [] elements= fAttributesContentProvider.getElements(null); 591 boolean oneElementSelected= fCurrentAttributeSelection.size() == 1; 592 if (elements.length == 0) { 593 status.setError(DebugUIMessages.EditLogicalStructureDialog_19); 594 } else if (oneElementSelected && fAttributeNameText.getText().trim().length() == 0) { 595 status.setError(DebugUIMessages.EditLogicalStructureDialog_20); 596 } else if (oneElementSelected && fSnippetDocument.get().trim().length() == 0) { 597 status.setError(DebugUIMessages.EditLogicalStructureDialog_21); 598 } else { 599 for (int i= 0; i < elements.length; i++) { 600 String [] variable= (String []) elements[i]; 601 if (variable[0].trim().length() == 0) { 602 status.setError(DebugUIMessages.EditLogicalStructureDialog_22); 603 break; 604 } 605 if (variable[1].trim().length() == 0) { 606 if (!oneElementSelected || fCurrentAttributeSelection.getFirstElement() != variable) { 607 status.setError(MessageFormat.format(DebugUIMessages.EditLogicalStructureDialog_23, new String [] {variable[0]})); 608 break; 609 } 610 } 611 } 612 } 613 } 614 if (!status.isError()) { 615 if (fType == null && fTypeSearched) { 616 status.setWarning(DebugUIMessages.EditLogicalStructureDialog_24); 617 } 618 } 619 updateStatus(status); 620 } 621 622 625 private void selectType() { 626 Shell shell= getShell(); 627 SelectionDialog dialog= null; 628 try { 629 dialog= JavaUI.createTypeDialog(shell, PlatformUI.getWorkbench().getProgressService(), 630 SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, 631 false, fQualifiedTypeNameText.getText()); 632 } catch (JavaModelException jme) { 633 String title= DebugUIMessages.DetailFormatterDialog_Select_type_6; 634 String message= DebugUIMessages.DetailFormatterDialog_Could_not_open_type_selection_dialog_for_detail_formatters_7; 635 ExceptionHandler.handle(jme, title, message); 636 return; 637 } 638 639 dialog.setTitle(DebugUIMessages.DetailFormatterDialog_Select_type_8); 640 dialog.setMessage(DebugUIMessages.DetailFormatterDialog_Select_a_type_to_format_when_displaying_its_detail_9); 641 if (dialog.open() == IDialogConstants.CANCEL_ID) { 642 return; 643 } 644 645 Object [] types= dialog.getResult(); 646 if (types != null && types.length > 0) { 647 fType = (IType)types[0]; 648 fQualifiedTypeNameText.setText(fType.getFullyQualifiedName()); 649 fTypeSearched = true; 650 } 651 } 652 653 656 public void documentAboutToBeChanged(DocumentEvent event) { 657 } 659 660 663 public void documentChanged(DocumentEvent event) { 664 checkValues(); 665 } 666 667 670 protected void okPressed() { 671 fLogicalStructure.setType(fQualifiedTypeNameText.getText().trim()); 673 fLogicalStructure.setDescription(fDescriptionText.getText().trim()); 674 fLogicalStructure.setSubtypes(fSubTypeButton.getSelection()); 675 if (fValueButton.getSelection()) { 676 fLogicalStructure.setValue(fSnippetDocument.get()); 677 } else { 678 saveAttributeValue(); 679 fLogicalStructure.setValue(null); 680 } 681 if (fAttributesContentProvider != null) { 682 fLogicalStructure.setVariables(fAttributesContentProvider.getElements()); 683 } 684 super.okPressed(); 685 } 686 687 691 private void findCorrespondingType() { 692 if (fTypeSearched) { 693 return; 694 } 695 fType= null; 696 fTypeSearched= true; 697 final String pattern= fQualifiedTypeNameText.getText().trim().replace('$', '.'); 698 if (pattern == null || "".equals(pattern)) { return; 700 } 701 final IProgressMonitor monitor = new NullProgressMonitor(); 702 final SearchRequestor collector = new SearchRequestor() { 703 private boolean fFirst= true; 704 705 public void endReporting() { 706 checkValues(); 707 } 708 709 public void acceptSearchMatch(SearchMatch match) throws CoreException { 710 Object enclosingElement = match.getElement(); 711 if (!fFirst) { 712 return; 713 } 714 fFirst= false; 715 if (enclosingElement instanceof IType) { 716 fType= (IType) enclosingElement; 717 } 718 monitor.setCanceled(true); 720 } 721 }; 722 723 SearchEngine engine= new SearchEngine(JavaCore.getWorkingCopies(null)); 724 SearchPattern searchPattern = SearchPattern.createPattern(pattern, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); 725 IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); 726 SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}; 727 try { 728 engine.search(searchPattern, participants, scope, collector, monitor); 729 } catch (CoreException e) { 730 JDIDebugUIPlugin.log(e); 731 } catch (OperationCanceledException e){ 732 } 733 } 734 735 738 public IType getType() { 739 if (!fTypeSearched) { 740 findCorrespondingType(); 741 } 742 return fType; 743 } 744 745 748 public boolean close() { 749 IWorkbench workbench = PlatformUI.getWorkbench(); 750 IHandlerService handlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class); 751 handlerService.deactivateHandler(fHandlerActivation); 752 753 fSnippetViewer.dispose(); 754 return super.close(); 755 } 756 757 } 758 | Popular Tags |