Skip to content

Package: EMFStoreUIProvider$3

EMFStoreUIProvider$3

nameinstructionbranchcomplexitylinemethod
widgetDefaultSelected(SelectionEvent)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
widgetSelected(SelectionEvent)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
{...}
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.emfstore.internal.ui;
16:
17: import java.util.ArrayList;
18:
19: import org.eclipse.core.runtime.NullProgressMonitor;
20: import org.eclipse.emf.ecp.core.util.ECPCheckoutSource;
21: import org.eclipse.emf.ecp.core.util.ECPProperties;
22: import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProjectWrapper;
23: import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider;
24: import org.eclipse.emf.ecp.spi.ui.DefaultUIProvider;
25: import org.eclipse.emf.emfstore.client.ESLocalProject;
26: import org.eclipse.emf.emfstore.client.ESRemoteProject;
27: import org.eclipse.emf.emfstore.client.exceptions.ESCertificateException;
28: import org.eclipse.emf.emfstore.internal.client.model.connectionmanager.KeyStoreManager;
29: import org.eclipse.emf.emfstore.internal.client.ui.views.emfstorebrowser.views.CertificateSelectionDialog;
30: import org.eclipse.emf.emfstore.server.exceptions.ESException;
31: import org.eclipse.jface.resource.ImageDescriptor;
32: import org.eclipse.jface.viewers.LabelProvider;
33: import org.eclipse.jface.window.Window;
34: import org.eclipse.swt.SWT;
35: import org.eclipse.swt.events.ModifyEvent;
36: import org.eclipse.swt.events.ModifyListener;
37: import org.eclipse.swt.events.SelectionEvent;
38: import org.eclipse.swt.events.SelectionListener;
39: import org.eclipse.swt.graphics.Image;
40: import org.eclipse.swt.layout.GridData;
41: import org.eclipse.swt.layout.GridLayout;
42: import org.eclipse.swt.widgets.Button;
43: import org.eclipse.swt.widgets.Composite;
44: import org.eclipse.swt.widgets.Control;
45: import org.eclipse.swt.widgets.Display;
46: import org.eclipse.swt.widgets.Label;
47: import org.eclipse.swt.widgets.Text;
48:
49: /**
50: * This class provides EMFStore specific UI.
51: *
52: * @author Eugen Neufeld
53: */
54: public class EMFStoreUIProvider extends DefaultUIProvider {
55:
56:         /**
57:          * The constructor.
58:          */
59:         public EMFStoreUIProvider() {
60:                 super(EMFStoreProvider.NAME);
61:         }
62:
63:         @Override
64:         @SuppressWarnings("unchecked")
65:         public <T> T getAdapter(Object adaptable, Class<T> adapterType) {
66:                 if (ESRemoteProject.class.isInstance(adaptable) && adapterType.equals(ESLocalProject.class)) {
67:                         final ESRemoteProject checkoutData = (ESRemoteProject) adaptable;
68:                         try {
69:                                 return (T) checkoutData.checkout(checkoutData.getProjectName(), new NullProgressMonitor());
70:                         } catch (final ESException e) {
71:                                 Activator.log(e);
72:                                 // BEGIN SUPRESS CATCH EXCEPTION
73:                         } catch (final RuntimeException e) {
74:                                 Activator.log(e);
75:                                 // END SUPRESS CATCH EXCEPTION
76:                         } finally {
77:                         }
78:                 }
79:                 return super.getAdapter(adaptable, adapterType);
80:         }
81:
82:         @Override
83:         public Control createCheckoutUI(Composite parent, ECPCheckoutSource checkoutSource,
84:                 ECPProperties projectProperties) {
85:                 return null;
86:         }
87:
88:         @Override
89:         public Control createAddRepositoryUI(Composite parent, final ECPProperties repositoryProperties,
90:                 final Text repositoryNameText, Text repositoryLabelText, Text repositoryDescriptionText) {
91:
92:                 final GridLayout mainLayout = new GridLayout(3, false);
93:                 mainLayout.marginWidth = 0;
94:                 mainLayout.marginHeight = 0;
95:
96:                 final Composite composite = new Composite(parent, SWT.NONE);
97:                 composite.setLayout(mainLayout);
98:                 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
99:
100:                 // use label width of main composite as minimum label width
101:                 final Label url = new Label(composite, 0);
102:                 url.setText(Messages.EMFStoreUIProvider_URL);
103:                 final int mcLabelWidth = parent.getParent().getChildren()[0].getSize().x;
104:                 if (mcLabelWidth > url.getSize().x) {
105:                         final GridData gdUrl = new GridData();
106:                         gdUrl.widthHint = mcLabelWidth;
107:                         url.setLayoutData(gdUrl);
108:                 }
109:
110:                 final Text urlText = new Text(composite, SWT.BORDER);
111:                 urlText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
112:                 urlText.addModifyListener(new ModifyListener() {
113:                         private String oldText = ""; //$NON-NLS-1$
114:
115:                         @Override
116:                         public void modifyText(ModifyEvent e) {
117:                                 if (oldText.equals(repositoryNameText.getText())) {
118:                                         oldText = urlText.getText();
119:                                         repositoryNameText.setText(oldText);
120:                                         repositoryProperties.addProperty(EMFStoreProvider.PROP_REPOSITORY_URL, oldText);
121:                                 }
122:                         }
123:                 });
124:
125:                 final Label port = new Label(composite, 0);
126:                 port.setText(Messages.EMFStoreUIProvider_Port);
127:                 final Text portText = new Text(composite, SWT.BORDER);
128:                 portText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
129:                 portText.addModifyListener(new ModifyListener() {
130:
131:                         @Override
132:                         public void modifyText(ModifyEvent e) {
133:                                 repositoryProperties.addProperty(EMFStoreProvider.PROP_PORT, portText.getText());
134:                         }
135:
136:                 });
137:
138:                 final Label cert = new Label(composite, 0);
139:                 cert.setText(Messages.EMFStoreUIProvider_Certificate);
140:                 final Text certificateText = new Text(composite, SWT.BORDER);
141:                 certificateText.setEditable(false);
142:                 certificateText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
143:
144:                 final Button bSelectCertificate = new Button(composite, SWT.PUSH);
145:                 // TODO change text
146:                 bSelectCertificate.setText(Messages.EMFStoreUIProvider_SelectCertificate);
147:                 bSelectCertificate.addSelectionListener(new SelectionListener() {
148:
149:                         @Override
150:                         public void widgetSelected(SelectionEvent e) {
151:                                 // open dialog
152:                                 final String certificate = selectCertificate();
153:                                 certificateText.setText(certificate);
154:                                 repositoryProperties.addProperty(EMFStoreProvider.PROP_CERTIFICATE, certificateText.getText());
155:
156:                         }
157:
158:                         @Override
159:                         public void widgetDefaultSelected(SelectionEvent e) {
160:                                 widgetSelected(e);
161:                         }
162:                 });
163:
164:                 urlText.setText("localhost"); //$NON-NLS-1$
165:                 portText.setText("8080"); //$NON-NLS-1$
166:                 certificateText.setText(KeyStoreManager.getInstance().getDefaultCertificate());
167:                 // else the certificate is not set
168:                 repositoryProperties.addProperty(EMFStoreProvider.PROP_CERTIFICATE, certificateText.getText());
169:                 return composite;
170:         }
171:
172:         /**
173:          * @return
174:          */
175:         private String selectCertificate() {
176:                 final CertificateSelectionDialog csd = new CertificateSelectionDialog(Display.getCurrent().getActiveShell(),
177:                         new LabelProvider() {
178:                                 @Override
179:                                 public String getText(Object element) {
180:                                         if (element instanceof String) {
181:                                                 return element.toString();
182:                                         }
183:
184:                                         return ""; //$NON-NLS-1$
185:
186:                                 }
187:                         });
188:                 ArrayList<String> certificates;
189:                 try {
190:                         certificates = KeyStoreManager.getInstance().getCertificates();
191:                         csd.setElements(certificates.toArray());
192:                 } catch (final ESCertificateException e1) {
193:                         csd.setErrorMessage(e1.getMessage());
194:                 }
195:                 csd.setBlockOnOpen(true);
196:                 csd.setTitle("Certificate Selection Dialog"); //$NON-NLS-1$
197:                 csd.open();
198:                 if (csd.getReturnCode() == Window.OK) {
199:                         return csd.getCertificateAlias();
200:                 }
201:                 return ""; //$NON-NLS-1$
202:         }
203:
204:         @Override
205:         public String getText(Object element) {
206:                 if (element instanceof EMFStoreProjectWrapper) {
207:                         final EMFStoreProjectWrapper emfStoreProjectWrapper = (EMFStoreProjectWrapper) element;
208:                         return emfStoreProjectWrapper.getDefaultCheckoutName();
209:                 }
210:
211:                 return super.getText(element);
212:         }
213:
214:         @Override
215:         public Image getImage(Object element) {
216:                 if (element instanceof EMFStoreProjectWrapper) {
217:                         return ImageDescriptor.createFromURL(
218:                                 Activator.getInstance().getBundle().getResource("icons/projectinfo.png")).createImage(); //$NON-NLS-1$
219:                 }
220:
221:                 return super.getImage(element);
222:         }
223:
224: }