1 11 package org.eclipse.debug.internal.ui.views.variables.details; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.ui.IDetailPane; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Label; 24 25 38 public class DetailPaneProxy { 39 40 43 private IDetailPane fCurrentPane; 44 45 48 private Control fCurrentControl; 49 50 53 private IDetailPaneContainer fParentContainer; 54 55 61 public DetailPaneProxy(IDetailPaneContainer parent){ 62 fParentContainer = parent; 63 } 64 65 73 public void display(IStructuredSelection selection){ 74 75 if ((selection == null || selection.isEmpty()) && fCurrentPane != null){ 76 fCurrentPane.display(selection); 77 return; 78 } 79 80 String preferredPaneID = DetailPaneManager.getDefault().getPreferredPaneFromSelection(selection); 81 82 if (fCurrentPane != null && preferredPaneID != null && preferredPaneID.equals(fCurrentPane.getID())){ 84 fCurrentPane.display(selection); 85 return; 86 } 87 88 setupPane(preferredPaneID, selection); 89 90 fParentContainer.paneChanged(preferredPaneID); 92 93 } 94 95 100 public boolean setFocus(){ 101 if (fCurrentPane != null){ 102 return fCurrentPane.setFocus(); 103 } 104 return false; 105 } 106 107 110 public void dispose(){ 111 if (fCurrentPane != null) fCurrentPane.dispose(); 112 if (fCurrentControl != null && !fCurrentControl.isDisposed()) fCurrentControl.dispose(); 113 } 114 115 121 public Object getAdapter(Class required){ 122 if (fCurrentPane != null && fCurrentPane instanceof IAdaptable){ 123 return ((IAdaptable)fCurrentPane).getAdapter(required); 124 } 125 else{ 126 return null; 127 } 128 } 129 130 public Control getCurrentControl(){ 131 return fCurrentControl; 132 } 133 134 public String getCurrentPaneID(){ 135 if (fCurrentPane != null){ 136 return fCurrentPane.getID(); 137 } 138 return null; 139 } 140 141 148 private void setupPane(String paneID, IStructuredSelection selection) { 149 if (fCurrentPane != null) fCurrentPane.dispose(); 150 if (fCurrentControl != null && !fCurrentControl.isDisposed()) fCurrentControl.dispose(); 151 if (paneID != null){ 152 fCurrentPane = DetailPaneManager.getDefault().getDetailPaneFromID(paneID); 153 if (fCurrentPane != null){ 154 fCurrentPane.init(fParentContainer.getWorkbenchPartSite()); 155 fCurrentControl = fCurrentPane.createControl(fParentContainer.getParentComposite()); 156 if (fCurrentControl != null){ 157 fParentContainer.getParentComposite().layout(true); 158 fCurrentPane.display(selection); 159 } else{ 160 createErrorLabel(DetailMessages.DetailPaneProxy_0); 161 DebugUIPlugin.log(new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), "The detail pane \""+ fCurrentPane.getID() + "\" did not create and return a control."))); } 163 } else { 164 createErrorLabel(DetailMessages.DetailPaneProxy_0); 165 DebugUIPlugin.log(new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), "Could not create the detail pane with ID " + paneID))); } 167 } else { 168 createErrorLabel(DetailMessages.DetailPaneProxy_1); 169 DebugUIPlugin.log(new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), "No detail panes could be found to display the current selection."))); } 171 } 172 173 178 private void createErrorLabel(String message){ 179 if (fCurrentPane != null) fCurrentPane.dispose(); 180 if (fCurrentControl != null && !fCurrentControl.isDisposed()) fCurrentControl.dispose(); 181 Label errorLabel = new Label(fParentContainer.getParentComposite(),SWT.LEFT); 182 errorLabel.setText(message); 183 errorLabel.setLayoutData(new GridData(GridData.FILL_BOTH)); 184 fCurrentControl = errorLabel; 185 fParentContainer.getParentComposite().layout(); 186 } 187 188 } 189 | Popular Tags |