Skip to content

Package: ManageAdditionalViewsDialog$3

ManageAdditionalViewsDialog$3

nameinstructionbranchcomplexitylinemethod
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: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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: package org.eclipse.emf.ecp.view.model.internal.preview;
15:
16: import java.util.Set;
17:
18: import org.eclipse.core.resources.IFile;
19: import org.eclipse.core.runtime.IPath;
20: import org.eclipse.core.runtime.IStatus;
21: import org.eclipse.core.runtime.Status;
22: import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
23: import org.eclipse.jface.dialogs.Dialog;
24: import org.eclipse.jface.layout.GridDataFactory;
25: import org.eclipse.jface.viewers.ArrayContentProvider;
26: import org.eclipse.jface.viewers.LabelProvider;
27: import org.eclipse.jface.viewers.ListViewer;
28: import org.eclipse.jface.window.Window;
29: import org.eclipse.swt.SWT;
30: import org.eclipse.swt.events.SelectionAdapter;
31: import org.eclipse.swt.events.SelectionEvent;
32: import org.eclipse.swt.layout.FillLayout;
33: import org.eclipse.swt.layout.GridLayout;
34: import org.eclipse.swt.widgets.Button;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Control;
37: import org.eclipse.swt.widgets.Label;
38: import org.eclipse.swt.widgets.Shell;
39: import org.eclipse.ui.dialogs.ISelectionStatusValidator;
40: import org.eclipse.ui.model.WorkbenchContentProvider;
41: import org.eclipse.ui.model.WorkbenchLabelProvider;
42:
43: /**
44: * Dialog for managing additional views for the preview.
45: *
46: * @author Eugen Neufeld
47: *
48: */
49: public class ManageAdditionalViewsDialog extends Dialog {
50:
51:         private final Set<IPath> knownViews;
52:
53:         /**
54:          * Default constructor.
55:          *
56:          * @param parentShell The Shell to create the dialog on
57:          * @param knownViews The Set of known views
58:          */
59:         public ManageAdditionalViewsDialog(Shell parentShell, Set<IPath> knownViews) {
60:                 super(parentShell);
61:                 setShellStyle(getShellStyle() | SWT.RESIZE);
62:                 this.knownViews = knownViews;
63:         }
64:
65:         @Override
66:         protected void configureShell(Shell shell) {
67:                 super.configureShell(shell);
68:                 shell.setText(Messages.ManageAdditionalViewsDialog_Title);
69:                 shell.setMinimumSize(300, 300);
70:         }
71:
72:         /**
73:          * {@inheritDoc}
74:          *
75:          * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
76:          */
77:         @Override
78:         protected Control createDialogArea(Composite parent) {
79:                 final Composite composite = (Composite) super.createDialogArea(parent);
80:                 composite.setLayout(new GridLayout(1, false));
81:                 final Label label = new Label(composite, SWT.NONE);
82:                 label.setText(Messages.ManageAdditionalViewsDialog_LoadedView);
83:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(label);
84:                 final ListViewer listViewer = new ListViewer(composite, SWT.SINGLE | SWT.BORDER);
85:                 listViewer.setContentProvider(ArrayContentProvider.getInstance());
86:                 listViewer.setLabelProvider(new LabelProvider() {
87:
88:                         /**
89:                          * {@inheritDoc}
90:                          *
91:                          * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
92:                          */
93:                         @Override
94:                         public String getText(Object element) {
95:                                 if (IPath.class.isInstance(element)) {
96:                                         return IPath.class.cast(element).toOSString();
97:                                 }
98:                                 return super.getText(element);
99:                         }
100:
101:                 });
102:                 listViewer.setInput(knownViews);
103:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(listViewer.getControl());
104:
105:                 final Composite buttons = new Composite(composite, SWT.NONE);
106:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(buttons);
107:                 buttons.setLayout(new FillLayout(SWT.HORIZONTAL));
108:                 final Button addView = new Button(buttons, SWT.PUSH);
109:                 addView.setText(Messages.ManageAdditionalViewsDialog_AddView);
110:                 addView.addSelectionListener(new SelectionAdapter() {
111:
112:                         @Override
113:                         public void widgetSelected(SelectionEvent e) {
114:                                 super.widgetSelected(e);
115:                                 final WorkspaceResourceDialog d = new WorkspaceResourceDialog(getShell(), new WorkbenchLabelProvider(),
116:                                         new WorkbenchContentProvider());
117:                                 d.setAllowMultiple(false);
118:                                 d.setValidator(new ISelectionStatusValidator() {
119:                                         @Override
120:                                         public IStatus validate(Object[] selection) {
121:                                                 if (selection == null || selection.length != 1 || !IFile.class.isInstance(selection[0])) {
122:                                                         return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
123:                                                                 Messages.ManageAdditionalViewsDialog_NoFileSelected);
124:                                                 }
125:                                                 if (IFile.class.cast(selection[0]).getFileExtension().equals("view")) { //$NON-NLS-1$
126:                                                         return Status.OK_STATUS;
127:                                                 }
128:                                                 return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
129:                                                         Messages.ManageAdditionalViewsDialog_NoViewModelSelected);
130:                                         }
131:                                 });
132:                                 d.loadContents();
133:                                 final int result = d.open();
134:                                 if (result == Window.OK) {
135:                                         knownViews.add(d.getSelectedFiles()[0].getFullPath());
136:                                         listViewer.refresh();
137:                                 }
138:                         }
139:                 });
140:
141:                 final Button removeView = new Button(buttons, SWT.PUSH);
142:                 removeView.setText(Messages.ManageAdditionalViewsDialog_RemoveView);
143:                 removeView.addSelectionListener(new SelectionAdapter() {
144:                         @Override
145:                         public void widgetSelected(SelectionEvent e) {
146:                                 super.widgetSelected(e);
147:                                 knownViews.remove(listViewer.getStructuredSelection().getFirstElement());
148:                                 listViewer.refresh();
149:                         }
150:                 });
151:
152:                 return composite;
153:         }
154:
155: }