1 11 package org.eclipse.team.ui; 12 13 import org.eclipse.compare.CompareEditorInput; 14 import org.eclipse.compare.CompareUI; 15 import org.eclipse.core.runtime.NullProgressMonitor; 16 import org.eclipse.jface.dialogs.*; 17 import org.eclipse.jface.dialogs.Dialog; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.custom.BusyIndicator; 20 import org.eclipse.swt.graphics.Point; 21 import org.eclipse.swt.widgets.*; 22 import org.eclipse.team.internal.ui.TeamUIMessages; 23 import org.eclipse.team.internal.ui.TeamUIPlugin; 24 import org.eclipse.ui.PlatformUI; 25 26 36 public class SaveablePartDialog extends TrayDialog { 37 38 private ISaveableWorkbenchPart input; 39 private String fContextId; 40 private boolean hasSettings = true; 41 42 49 public SaveablePartDialog(Shell shell, ISaveableWorkbenchPart input) { 50 super(shell); 51 setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); 52 this.input = input; 53 } 54 55 58 protected void createButtonsForButtonBar(Composite parent) { 59 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 60 } 61 62 65 protected Control createDialogArea(Composite parent2) { 66 Composite parent = (Composite) super.createDialogArea(parent2); 67 input.createPartControl(parent); 68 Shell shell = getShell(); 69 shell.setText(input.getTitle()); 70 shell.setImage(input.getTitleImage()); 71 Dialog.applyDialogFont(parent2); 72 return parent; 73 } 74 75 78 public boolean close() { 79 saveChanges(); 80 return super.close(); 81 } 82 83 86 private void saveChanges() { 87 MessageDialog dialog = new MessageDialog( 88 getShell(), TeamUIMessages.ParticipantCompareDialog_2, null, 89 TeamUIMessages.ParticipantCompareDialog_3, MessageDialog.QUESTION, new String []{IDialogConstants.YES_LABEL, 90 IDialogConstants.NO_LABEL}, 0); 92 if (input.isDirty() && dialog.open() == IDialogConstants.OK_ID) { 93 BusyIndicator.showWhile(null, new Runnable () { 94 public void run() { 95 input.doSave(new NullProgressMonitor()); 96 } 97 }); 98 } 99 } 100 101 106 protected ISaveableWorkbenchPart getInput() { 107 return input; 108 } 109 110 113 protected IDialogSettings getDialogBoundsSettings() { 114 IDialogSettings compareSettings = TeamUIPlugin.getPlugin().getDialogSettings(); 115 String sectionName = this.getClass().getName(); 116 IDialogSettings dialogSettings = compareSettings.getSection(sectionName); 117 if (dialogSettings == null) { 118 hasSettings = false; 119 dialogSettings = compareSettings.addNewSection(sectionName); 120 } 121 return dialogSettings; 122 } 123 124 128 public void setHelpContextId(String contextId) { 129 fContextId= contextId; 130 } 131 132 135 protected void configureShell(Shell newShell) { 136 super.configureShell(newShell); 137 if (fContextId != null) 138 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, fContextId); 139 } 140 141 144 protected Point getInitialSize() { 145 Point initialSize = super.getInitialSize(); 146 if (hasSettings) { 147 return initialSize; 148 } 149 int width= 0; 152 int height= 0; 153 Shell shell= getParentShell(); 154 if (shell != null) { 155 Point parentSize= shell.getSize(); 156 width= parentSize.x-100; 157 height= parentSize.y-100; 158 } 159 if (width < 700) 160 width= 700; 161 if (height < 500) 162 height= 500; 163 return new Point(width, height); 164 } 165 } 166 | Popular Tags |