1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import java.text.DateFormat ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.dialogs.IDialogSettings; 19 import org.eclipse.jface.viewers.ColumnWeightData; 20 import org.eclipse.jface.viewers.TableLayout; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.graphics.Point; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Shell; 30 import org.eclipse.update.core.SiteManager; 31 import org.eclipse.update.internal.core.InstallConfiguration; 32 import org.eclipse.update.internal.ui.UpdateUI; 33 import org.eclipse.update.internal.ui.UpdateUIMessages; 34 35 36 37 public class ShowActivitiesDialog extends Dialog { 38 private TableViewer activitiesViewer; 39 40 private IDialogSettings dialogSettings; 42 private Point dialogLocation; 43 private Point dialogSize; 44 45 48 public ShowActivitiesDialog(Shell parentShell) { 49 super(parentShell); 50 setShellStyle(SWT.RESIZE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL); 51 readConfiguration(); 52 } 53 54 public void create() { 55 super.create(); 56 if (dialogLocation != null) 58 getShell().setLocation(dialogLocation); 59 60 if (dialogSize != null) 62 getShell().setSize(dialogSize); 63 else 64 getShell().setSize(500,500); 65 66 67 applyDialogFont(buttonBar); 68 getButton(IDialogConstants.OK_ID).setFocus(); 69 } 70 71 protected Control createDialogArea(Composite parent) { 72 Composite container = new Composite(parent, SWT.NONE); 73 GridLayout layout = new GridLayout(); 74 layout.numColumns = 1; 75 layout.makeColumnsEqualWidth = false; 76 container.setLayout(layout); 77 GridData gd = new GridData(GridData.FILL_BOTH); 78 gd.grabExcessHorizontalSpace = true; 79 gd.grabExcessVerticalSpace = true; 80 container.setLayoutData(gd); 81 createDescriptionSection(container); 82 createActivitiesViewer(container); 83 Dialog.applyDialogFont(container); 84 return container; 85 } 86 87 protected Control createDescriptionSection(Composite parent){ 88 Composite container = new Composite(parent, SWT.NONE); 89 GridLayout layout = new GridLayout(); 90 layout.numColumns = 2; 91 layout.makeColumnsEqualWidth = false; 92 container.setLayout(layout); 93 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 94 container.setLayoutData(gd); 95 try { 96 Label targetLabel = new Label(container, SWT.NONE); 97 targetLabel.setText(UpdateUIMessages.ShowActivitiesDialog_date); 98 Label target = new Label(container, SWT.NONE); 99 DateFormat df = DateFormat.getDateTimeInstance(); 100 String localizedDate = df.format(SiteManager.getLocalSite().getCurrentConfiguration().getCreationDate()); 101 target.setText(localizedDate); 102 103 Label urlLabel = new Label(container, SWT.NONE); 104 urlLabel.setText(UpdateUIMessages.ShowActivitiesDialog_loc); 105 Label url = new Label(container, SWT.NONE); 106 url.setText(((InstallConfiguration)SiteManager.getLocalSite().getCurrentConfiguration()).getURL().getFile()); 107 108 109 } catch (CoreException e) { 110 UpdateUI.logException(e); 111 } 112 return container; 113 } 114 protected Control createActivitiesViewer(Composite parent) { 115 Composite composite = new Composite(parent, SWT.NONE); 116 GridLayout gridLayout = new GridLayout(); 117 gridLayout.marginHeight = gridLayout.marginWidth = 4; 118 composite.setLayout(gridLayout); 119 120 GridData gd = new GridData(GridData.FILL_BOTH); 121 124 composite.setLayoutData(gd); 125 126 127 Label label = new Label(composite, SWT.NONE); 128 label.setText(UpdateUIMessages.ShowActivitiesDialog_label); 129 activitiesViewer = ActivitiesTableViewer.createViewer(composite, true); 130 131 TableLayout layout = new TableLayout(); 132 layout.addColumnData(new ColumnWeightData(8, 20, false)); 133 layout.addColumnData(new ColumnWeightData(50, 160, true)); 134 layout.addColumnData(new ColumnWeightData(50, 183, true)); 135 layout.addColumnData(new ColumnWeightData(50, 100, true)); 136 137 activitiesViewer.getTable().setLayout(layout); 138 try { 139 activitiesViewer.setInput(SiteManager.getLocalSite().getCurrentConfiguration()); 140 } catch (CoreException e) { 141 } 142 Dialog.applyDialogFont(composite); 143 return composite; 144 } 145 146 protected void createButtonsForButtonBar(Composite parent) { 147 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 149 } 150 151 public boolean close() { 152 storeSettings(); 153 return super.close(); 154 } 155 156 160 private void storeSettings() { 161 writeConfiguration(); 162 } 163 169 private IDialogSettings getDialogSettings() { 170 IDialogSettings settings = UpdateUI.getDefault().getDialogSettings(); 171 dialogSettings = settings.getSection(getClass().getName()); 172 if (dialogSettings == null) 173 dialogSettings= settings.addNewSection(getClass().getName()); 174 return dialogSettings; 175 } 176 177 181 private void readConfiguration() { 182 IDialogSettings s= getDialogSettings(); 183 try { 184 int x= s.getInt("x"); int y= s.getInt("y"); dialogLocation= new Point(x, y); 187 188 x = s.getInt("width"); y = s.getInt("height"); dialogSize = new Point(x,y); 191 } catch (NumberFormatException e) { 192 dialogLocation= null; 193 dialogSize = null; 194 } 195 } 196 197 private void writeConfiguration(){ 198 IDialogSettings s = getDialogSettings(); 199 Point location = getShell().getLocation(); 200 s.put("x", location.x); s.put("y", location.y); 203 Point size = getShell().getSize(); 204 s.put("width", size.x); s.put("height", size.y); } 207 } 208 | Popular Tags |