Skip to content

Package: UnknownFeaturesDialog$InputElement

UnknownFeaturesDialog$InputElement

nameinstructionbranchcomplexitylinemethod
UnknownFeaturesDialog.InputElement(UnknownFeaturesDialog, String, String)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getObjectName()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getObjectType()
M: 3 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-2014 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ide.editor.view;
15:
16: import java.util.ArrayList;
17: import java.util.Iterator;
18: import java.util.List;
19: import java.util.Map;
20: import java.util.Map.Entry;
21:
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.util.FeatureMap;
24: import org.eclipse.emf.ecore.xml.type.AnyType;
25: import org.eclipse.jface.dialogs.Dialog;
26: import org.eclipse.jface.viewers.ArrayContentProvider;
27: import org.eclipse.jface.viewers.ColumnLabelProvider;
28: import org.eclipse.jface.viewers.TableViewer;
29: import org.eclipse.jface.viewers.TableViewerColumn;
30: import org.eclipse.swt.SWT;
31: import org.eclipse.swt.graphics.Point;
32: import org.eclipse.swt.graphics.Rectangle;
33: import org.eclipse.swt.layout.FillLayout;
34: import org.eclipse.swt.layout.GridData;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Control;
37: import org.eclipse.swt.widgets.Event;
38: import org.eclipse.swt.widgets.Label;
39: import org.eclipse.swt.widgets.Listener;
40: import org.eclipse.swt.widgets.Shell;
41: import org.eclipse.swt.widgets.Table;
42: import org.eclipse.swt.widgets.TableColumn;
43: import org.eclipse.swt.widgets.TableItem;
44: import org.eclipse.swt.widgets.Text;
45:
46: /**
47: * @author Alexandra Buzila
48: *
49: */
50: public class UnknownFeaturesDialog extends Dialog {
51:         /** The unresolved features. */
52:         private final Map<EObject, AnyType> objects;
53:         /** The dialog description. */
54:         private String description;
55:
56:         private final String title;
57:
58:         /**
59:          * @param parentShell the shell for creating the dialog
60:          * @param title the title of the dialog
61:          * @param objects the map of unresolved {@link EObject}s and their corresponding {@link AnyType}
62:          */
63:         protected UnknownFeaturesDialog(Shell parentShell, String title, Map<EObject, AnyType> objects) {
64:                 super(parentShell);
65:                 this.objects = objects;
66:                 this.title = title;
67:                 setDescription("The following features could not be migrated:"); //$NON-NLS-1$
68:
69:         }
70:
71:         @Override
72:         protected void configureShell(Shell shell) {
73:                 super.configureShell(shell);
74:                 shell.setText(title);
75:         }
76:
77:         @Override
78:         protected Control createDialogArea(Composite parent) {
79:                 final Composite composite = (Composite) super.createDialogArea(parent);
80:
81:                 final Label label = new Label(composite, SWT.WRAP);
82:                 label.setText(getDescription());
83:
84:                 final TableViewer viewer = new TableViewer(parent, SWT.H_SCROLL
85:                         | SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER);
86:                 final Table table = viewer.getTable();
87:                 table.setHeaderVisible(true);
88:                 table.setLinesVisible(false);
89:                 table.setToolTipText(""); //$NON-NLS-1$
90:                 final Listener tableListener = getTableListener(composite, table);
91:                 table.addListener(SWT.Dispose, tableListener);
92:                 table.addListener(SWT.KeyDown, tableListener);
93:                 table.addListener(SWT.MouseMove, tableListener);
94:                 table.addListener(SWT.MouseHover, tableListener);
95:
96:                 viewer.setContentProvider(ArrayContentProvider.getInstance());
97:                 viewer.setInput(getInput());
98:                 createColumns(parent, viewer);
99:
100:                 final GridData gridData = new GridData();
101:                 gridData.verticalAlignment = GridData.FILL;
102:                 gridData.horizontalSpan = 2;
103:                 gridData.grabExcessHorizontalSpace = true;
104:                 gridData.grabExcessVerticalSpace = true;
105:                 gridData.horizontalAlignment = GridData.FILL;
106:                 viewer.getControl().setLayoutData(gridData);
107:
108:                 viewer.refresh(true);
109:                 composite.layout();
110:                 return composite;
111:         }
112:
113:         private Listener getLabelListener(final Table table) {
114:                 return new Listener() {
115:                         @Override
116:                         public void handleEvent(Event event) {
117:                                 final Text label = (Text) event.widget;
118:                                 final Shell shell = label.getShell();
119:                                 switch (event.type) {
120:                                 case SWT.MouseDown:
121:                                         final Event e = new Event();
122:                                         e.item = (TableItem) label.getData("_TABLEITEM"); //$NON-NLS-1$
123:                                         table.setSelection(new TableItem[] { (TableItem) e.item });
124:                                         table.notifyListeners(SWT.Selection, e);
125:                                         shell.dispose();
126:                                         table.setFocus();
127:                                         break;
128:                                 case SWT.MouseExit:
129:                                         shell.dispose();
130:                                         break;
131:                                 default:
132:                                         break;
133:                                 }
134:                         }
135:                 };
136:         }
137:
138:         private Listener getTableListener(final Composite composite, final Table table) {
139:                 return new TableListener(table, composite);
140:         }
141:
142:         /**
143:          * @return
144:          */
145:         private List<InputElement> getInput() {
146:                 final List<InputElement> input = new ArrayList<InputElement>();
147:                 for (final Iterator<Entry<EObject, AnyType>> itr = getObjects().entrySet().iterator(); itr
148:                         .hasNext();) {
149:                         final Entry<EObject, AnyType> entry = itr.next();
150:                         final AnyType value = entry.getValue();
151:                         final FeatureMap mixed = value.getMixed();
152:                         for (int i = 0; i < mixed.size(); i++) {
153:                                 final AnyType object = (AnyType) mixed.getValue(i);
154:                                 final FeatureMap anyAttribute2 = object.getAnyAttribute();
155:                                 final FeatureMap mixed2 = object.getMixed();
156:                                 for (int i1 = 0; i1 < anyAttribute2.size(); i1++) {
157:                                         final String vvalue = (String) anyAttribute2.getValue(i1);
158:                                         input.add(new InputElement(object.eClass().getName(), vvalue));
159:                                         vvalue.toString();
160:                                 }
161:                                 for (int i1 = 0; i1 < mixed2.size(); i1++) {
162:                                         if (AnyType.class.isInstance(mixed2.getValue(i1))) {
163:                                                 final String value2 = mixed2.getEStructuralFeature(i1).getName();
164:                                                 final String object2 = mixed2.getValue(i1).toString();
165:                                                 input.add(new InputElement(object2, value2));
166:                                         }
167:                                 }
168:                         }
169:                 }
170:                 return input;
171:         }
172:
173:         /**
174:          * @param parent
175:          * @param viewer
176:          */
177:         private void createColumns(Composite parent, TableViewer viewer) {
178:                 final String[] titles = { "Type", "Name", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
179:                 final int[] bounds = { 200, 200 };
180:
181:                 for (final TableColumn column : viewer.getTable().getColumns()) {
182:                         column.dispose();
183:                 }
184:
185:                 TableViewerColumn col = createTableViewerColumn(viewer, titles[0], bounds[0], 0);
186:                 col.setLabelProvider(new ColumnLabelProvider() {
187:                         @Override
188:                         public String getText(Object element) {
189:                                 final InputElement inputEl = (InputElement) element;
190:                                 return inputEl.getObjectType();
191:                         }
192:                 });
193:
194:                 col = createTableViewerColumn(viewer, titles[1], bounds[1], 1);
195:                 col.setLabelProvider(new ColumnLabelProvider() {
196:                         @Override
197:                         public String getText(Object element) {
198:                                 final InputElement inputEl = (InputElement) element;
199:                                 return inputEl.getObjectName();
200:                         }
201:                 });
202:         }
203:
204:         private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound,
205:                 final int colNumber) {
206:                 final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
207:                         SWT.NONE);
208:                 final TableColumn column = viewerColumn.getColumn();
209:                 column.setText(title);
210:                 column.setWidth(bound);
211:                 column.setResizable(true);
212:                 column.setMoveable(true);
213:                 return viewerColumn;
214:         }
215:
216:         @Override
217:         public boolean close() {
218:                 // stuff goes here
219:                 // ....
220:                 return super.close();
221:         }
222:
223:         /**
224:          * @return the description
225:          */
226:         public String getDescription() {
227:                 return description;
228:         }
229:
230:         /**
231:          * @param description the description to set
232:          */
233:         public void setDescription(String description) {
234:                 this.description = description;
235:         }
236:
237:         /**
238:          * @return the objects
239:          */
240:         public Map<EObject, AnyType> getObjects() {
241:                 return objects;
242:         }
243:
244:         /**
245:          * @author Jonas
246:          *
247:          */
248:         private final class TableListener implements Listener {
249:                 private final Table table;
250:                 private final Composite composite;
251:                 private Shell tip;
252:                 private Text text;
253:
254:                 /**
255:                  * @param table
256:                  * @param composite
257:                  */
258:                 private TableListener(Table table, Composite composite) {
259:                         this.table = table;
260:                         this.composite = composite;
261:                 }
262:
263:                 @Override
264:                 public void handleEvent(Event event) {
265:                         switch (event.type) {
266:                         case SWT.Dispose: {
267:                                 break;
268:                         }
269:                         case SWT.KeyDown: {
270:                                 break;
271:                         }
272:                         case SWT.MouseMove: {
273:                                 if (tip == null) {
274:                                         break;
275:                                 }
276:                                 tip.dispose();
277:                                 tip = null;
278:                                 text = null;
279:                                 break;
280:                         }
281:                         case SWT.MouseHover: {
282:                                 final TableItem item = table.getItem(new Point(event.x, event.y));
283:                                 if (item != null) {
284:                                         if (tip != null && !tip.isDisposed()) {
285:                                                 tip.dispose();
286:                                         }
287:                                         tip = new Shell(composite.getShell(), SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS);
288:                                         tip.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
289:                                         final FillLayout layout = new FillLayout();
290:                                         layout.marginWidth = 2;
291:                                         tip.setLayout(layout);
292:
293:                                         text = new Text(tip, SWT.MULTI);
294:                                         text.setForeground(composite.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
295:                                         text.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
296:                                         text.setData("_TABLEITEM", item); //$NON-NLS-1$
297:                                         text.setText(item.getText());
298:                                         text.setEditable(false);
299:
300:                                         text.addListener(SWT.MouseExit, getLabelListener(table));
301:                                         final Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
302:                                         final Rectangle rect = item.getBounds(0);
303:                                         final Point pt = table.toDisplay(rect.x, rect.y);
304:                                         tip.setBounds(pt.x, pt.y, size.x, size.y);
305:                                         tip.setVisible(true);
306:                                 }
307:                                 break;
308:                         }
309:                         default:
310:                                 break;
311:                         }
312:                 }
313:         }
314:
315:         /** The dialog's TableViewer's input elements. */
316:         private class InputElement {
317:                 private final String objectType;
318:
319:                 /**
320:                  * @return the objectType
321:                  */
322:                 public String getObjectType() {
323:                         return objectType;
324:                 }
325:
326:                 private final String objectName;
327:
328:                 /**
329:                  * @return the objectName
330:                  */
331:                 public String getObjectName() {
332:                         return objectName;
333:                 }
334:
335:                 InputElement(String type, String name) {
336:                         objectType = type;
337:                         objectName = name;
338:                 }
339:
340:         }
341:
342: }