1 21 22 package org.apache.derby.ui.properties; 23 24 import org.apache.derby.ui.common.CommonNames; 25 import org.apache.derby.ui.common.Messages; 26 import org.apache.derby.ui.util.DerbyServerUtils; 27 import org.apache.derby.ui.util.Logger; 28 import org.apache.derby.ui.util.SelectionUtil; 29 import org.eclipse.core.resources.IProject; 30 import org.eclipse.core.runtime.CoreException; 31 import org.eclipse.core.runtime.IStatus; 32 import org.eclipse.jface.dialogs.MessageDialog; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.graphics.Color; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.layout.GridLayout; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.swt.widgets.Shell; 41 import org.eclipse.swt.widgets.Text; 42 import org.eclipse.ui.dialogs.PropertyPage; 43 44 45 46 public class DerbyPropertiesPage extends PropertyPage { 47 public DerbyPropertiesPage() { 48 super(); 49 } 50 protected DerbyProperties dsProps; 51 protected Text hostText; 52 protected Text portText; 53 protected Text systemHomeText; 54 private boolean isServerRunning; 55 56 57 protected void addControls(Composite parent) { 58 Composite composite = createDefaultComposite(parent); 59 60 Label txt=new Label(composite,SWT.NONE); 62 txt.setBackground(new Color(null,0,0,0)); 63 txt.setForeground(new Color(null,255,255,255)); 64 txt.setText("Network Server Settings:"); 65 66 Label separatorLabel=new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); 68 separatorLabel.setLayoutData(getSeperatorLabelGridData()); 69 70 org.eclipse.swt.widgets. 71 Label portLabel = new Label(composite, SWT.NONE); 72 portLabel.setText("&Network Server Port:"); 73 portText = new Text(composite, SWT.SINGLE | SWT.BORDER); 74 GridData gd = new GridData(); 75 gd.widthHint = convertWidthInCharsToPixels(6); 76 portText.setLayoutData(gd); 77 78 Label hostLabel = new Label(composite, SWT.NONE); 79 hostLabel.setText("&Network Server Host:"); 80 hostText = new Text(composite, SWT.SINGLE | SWT.BORDER); 81 gd = new GridData(); 82 gd.widthHint = convertWidthInCharsToPixels(16); 83 hostText.setLayoutData(gd); 84 85 separatorLabel=new Label(composite, SWT.NONE); 87 separatorLabel.setLayoutData(getSeperatorLabelGridData()); 88 separatorLabel.setText(""); 89 90 Label txt1=new Label(composite,SWT.NONE); 91 txt1.setBackground(new Color(null,0,0,0)); 92 txt1.setForeground(new Color(null,255,255,255)); 93 txt1.setText("Derby System Properties:"); 94 95 separatorLabel=new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); 97 separatorLabel.setLayoutData(getSeperatorLabelGridData()); 98 99 Label sytemHomeLabel = new Label(composite, SWT.NONE); 100 sytemHomeLabel.setText("&derby.system.home="); 101 systemHomeText = new Text(composite, SWT.SINGLE | SWT.BORDER); 102 gd = new GridData(); 103 gd.widthHint = convertWidthInCharsToPixels(16); 104 systemHomeText.setLayoutData(gd); 105 } 106 107 protected Composite createDefaultComposite(Composite parent) { 108 Composite composite = new Composite(parent, SWT.NULL); 109 GridLayout layout = new GridLayout(); 110 layout.numColumns = 2; 111 composite.setLayout(layout); 112 113 GridData data = new GridData(); 114 data.verticalAlignment = GridData.FILL; 115 data.horizontalAlignment = GridData.FILL; 116 composite.setLayoutData(data); 117 118 return composite; 119 } 120 121 protected void fillControls() { 122 portText.setText(Integer.toString(dsProps.getPort())); 123 hostText.setText(dsProps.getHost()); 124 systemHomeText.setText(dsProps.getSystemHome()); 125 isServerRunning = checkServer(); 126 if (isServerRunning) { 129 portText.setEditable(false); 130 hostText.setEditable(false); 131 systemHomeText.setEditable(false); 132 } 133 } 134 135 protected boolean checkServer() { 136 IProject proj = (IProject)getElement(); 137 boolean serverRunning = false; 138 try { 139 serverRunning = DerbyServerUtils.getDefault().getRunning(proj); 140 } 141 catch (CoreException ce) { 142 Logger.log(SelectionUtil.getStatusMessages(ce),IStatus.ERROR); 143 } 144 return serverRunning; 145 } 146 147 protected void getParams() { 148 dsProps = new DerbyProperties(); 149 try { 150 dsProps.setPort(Integer.parseInt(portText.getText())); 151 } 152 catch (NumberFormatException ne) { 153 } 155 dsProps.setHost(hostText.getText()); 156 dsProps.setSystemHome(systemHomeText.getText()); 157 158 if (isServerRunning) { 161 Shell shell = new Shell(); 162 MessageDialog.openInformation( 163 shell, 164 CommonNames.PLUGIN_NAME, 165 Messages.SERVER_RUNNING ); 166 } 167 } 168 169 protected GridData getSeperatorLabelGridData() { 170 171 GridData gridData = new GridData(GridData.BEGINNING | 172 GridData.HORIZONTAL_ALIGN_FILL | 173 GridData.GRAB_VERTICAL | 174 GridData.BEGINNING | 175 GridData.VERTICAL_ALIGN_BEGINNING | 176 GridData.VERTICAL_ALIGN_FILL) ; 177 gridData.horizontalSpan = 2; 178 gridData.grabExcessVerticalSpace = false; 179 gridData.grabExcessHorizontalSpace = true; 180 return gridData; 181 182 } 183 184 protected void performDefaults() { 185 dsProps = new DerbyProperties(); 186 fillControls(); 187 } 188 public boolean performOk() { 189 IProject proj = (IProject)getElement(); 190 getParams(); 191 try { 192 193 dsProps.save(proj.getProject()); 194 } 195 catch (CoreException ce) { 196 System.err.println(SelectionUtil.getStatusMessages(ce)); 197 return false; 198 } 199 return true; 200 } 201 202 protected Control createContents(Composite parent) { 203 Composite composite = new Composite(parent, SWT.NONE); 204 GridLayout layout = new GridLayout(); 205 composite.setLayout(layout); 206 GridData data = new GridData(GridData.FILL); 207 data.grabExcessHorizontalSpace = true; 208 composite.setLayoutData(data); 209 addControls(composite); 210 IProject proj = (IProject)getElement(); 211 try { 212 dsProps = new DerbyProperties(proj); 213 fillControls(); 214 } 215 catch (CoreException ce) { 216 Logger.log(SelectionUtil.getStatusMessages(ce),IStatus.ERROR); 217 } 218 return composite; 219 } 220 221 } 222 | Popular Tags |