Commit c0ba71bb authored by Liana Soima's avatar Liana Soima
Browse files

Utils package cleaned



Added classes: MultiPageWizard, DropDownDiaog, and other classes from
utils package from the old branch were added.
Signed-off-by: Liana Soima's avatarLiana Soima <soima@fortiss.org>
Issue-Ref: 3986
parent c74048dc
......@@ -16,17 +16,22 @@
package org.fortiss.af3.safetycases.ui.utils;
import static java.util.Arrays.asList;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.eclipse.swt.widgets.Display.getCurrent;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.AllocationTableCollection;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.mira.model.Analysis;
......@@ -38,6 +43,8 @@ import org.fortiss.af3.mode.model.ModeAutomaton;
import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationTable;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.Change;
import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateAutomaton;
import org.fortiss.tooling.base.model.base.HierarchicElementBase;
......@@ -420,4 +427,143 @@ public class AF3SelectionDialogUtils {
}
return selected;
}
/**
* opens a dialog for selecting on component which is referenced to the argument element
*
* @param shell
* @param root
* @param selected
* @return list of components
*/
public static Component selectComponent(final Shell shell, List<? extends EObject> root,
Component selected) {
ElementTreeSingleSelectDialog dialog = new ElementTreeSingleSelectDialog(shell, root,
selected, new ModelElementTreeContentProvider(root) {
/** {@inheritDoc} */
@Override
public List<? extends EObject> getChildren(EObject parent) {
return pickInstanceOf(asList(
new Class<?>[] {ComponentArchitecture.class, Component.class}),
super.getChildren(parent));
}
}, new ModelElementLabelProvider(), null) {
/** {@inheritDoc} */
@Override
public boolean acceptElement(Object element) {
return element instanceof Component;
}
};
if(Window.OK == dialog.open()) {
return (Component)dialog.getSelectedElement();
}
return selected;
}
/**
* opens a dialog for selecting on component which is referenced to the argument element
*
* @param shell
* @param root
* @param alreadyReferenced
* @param selected
* @return list of components
*/
public static List<Object> selectMultipleReferences(final Shell shell,
List<? extends EObject> root, List<EObject> alreadyReferenced, EObject selected) {
ElementTreeMultiSelectDialog d = new ElementTreeMultiSelectDialog(shell, root,
alreadyReferenced, new ModelElementTreeContentProvider(root) {
/** {@inheritDoc} */
@Override
public List<? extends EObject> getChildren(EObject parent) {
List<ModeAutomaton> modeAutomata = new ArrayList<ModeAutomaton>();
List<StateAutomaton> stateAutomata = new ArrayList<StateAutomaton>();
if(parent instanceof Component) {
modeAutomata = pickInstanceOf(ModeAutomaton.class,
((Component)parent).getSpecifications());
stateAutomata = pickInstanceOf(StateAutomaton.class,
((Component)parent).getSpecifications());
}
List<? extends EObject> elements = pickInstanceOf(asList(new Class<?>[] {
RequirementsContainer.class, RequirementsPackage.class,
Requirement.class, ComponentArchitecture.class, Component.class,
PlatformArchitecture.class, IPlatformArchitectureElement.class,
AllocationTableCollection.class, AllocationTable.class}),
super.getChildren(parent));
List<EObject> list = new ArrayList<EObject>();
list.addAll(elements);
for(ModeAutomaton ma : modeAutomata) {
list.addAll(ma.getRootMode().getSubModes());
}
for(StateAutomaton state : stateAutomata) {
list.addAll(state.getRootState().getSubStates());
}
return list;
}
}, new ModelElementLabelProvider());
if(Window.OK == d.open()) {
List<Change> changes = ((ArgumentElement)selected).getAffectedByCurrentChanges();
List<Object> impactedElements = new ArrayList<Object>();
for(Change change : changes) {
impactedElements.add(change.getModelElement());
}
List<Object> selectedElements = d.getSelectedElements();
if(!selectedElements.containsAll(impactedElements)) {
boolean go = openConfirm(getCurrent().getActiveShell(), "",
"You have impacted changes, that references System Model Elements, which are not set as connected to this Argument Element. Would you like to add them to the referenced list?");
if(go) {
selectedElements.addAll(
impactedElements.stream().filter(i -> !selectedElements.contains(i))
.collect(Collectors.toList()));
return selectedElements;
}
}
return d.getSelectedElements();
}
return null;
}
/**
* @param shell
* @param root
* @param selected
* @return dialog
*/
public static EObject selectSystemModelElement(final Shell shell, List<? extends EObject> root,
EObject selected) {
ElementTreeSingleSelectDialog dialog = new ElementTreeSingleSelectDialog(shell, root,
selected, new ModelElementTreeContentProvider(root) {
/** {@inheritDoc} */
@Override
public List<? extends EObject> getChildren(EObject parent) {
List<ModeAutomaton> modeAutomata = new ArrayList<ModeAutomaton>();
List<StateAutomaton> stateAutomata = new ArrayList<StateAutomaton>();
if(parent instanceof Component) {
modeAutomata = pickInstanceOf(ModeAutomaton.class,
((Component)parent).getSpecifications());
stateAutomata = pickInstanceOf(StateAutomaton.class,
((Component)parent).getSpecifications());
}
return pickInstanceOf(asList(new Class<?>[] {Requirement.class,
ComponentArchitecture.class, Component.class,
PlatformArchitecture.class, IPlatformArchitectureElement.class,
AllocationTableCollection.class, AllocationTable.class,
IPlatformArchitectureElement.class}), super.getChildren(parent));
}
}, new ModelElementLabelProvider(), null) {
/** {@inheritDoc} */
@Override
public boolean acceptElement(Object element) {
return element instanceof Component || element instanceof Requirement ||
element instanceof Mode || element instanceof AllocationTable ||
element instanceof State || element instanceof PlatformArchitecture ||
element instanceof IPlatformArchitectureElement;
}
};
if(Window.OK == dialog.open()) {
return (EObject)dialog.getSelectedElement();
}
return selected;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safetycases.ui.utils;
import java.util.List;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
* This dialog offers a dropdownList to select from.
*
* @author liana
*/
public class DropdownDialog extends Dialog {
/** The title of the dialog. */
private String title;
/** The message to display, or <code>null</code> if none. */
private String message;
/** roots of the tree. */
private List<String> itemNames;
/** The GUI composite. */
private DropdownDialogGUI gui;
/** The item selected from the dropDown list. */
private String selection;
/** Drop-down list for predefined Type of Changes. */
private Combo dropDownList;
/** Listener for changes in the DropDownList. */
@SuppressWarnings("unused")
private ModifyListener listener;
/** Constructor. */
public DropdownDialog(Shell parentShell, String dialogTitle, String dialogMessage,
List<String> buttonNames) {
super(parentShell);
this.title = dialogTitle;
this.message = dialogMessage;
this.itemNames = buttonNames;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
/** {@inheritDoc} */
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
if(title != null) {
shell.setText(title);
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
/** {@inheritDoc} */
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create Cancel buttons by default
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
// create composite
Composite composite = (Composite)super.createDialogArea(parent);
// create message
if(message != null) {
Label label = new Label(composite, SWT.WRAP);
label.setText(message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL |
GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.widthHint =
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
}
gui = new DropdownDialogGUI(composite, SWT.NONE);
FillLayout fillLayout = new FillLayout();
fillLayout.type = SWT.VERTICAL;
gui.setLayout(fillLayout);
String[] stockArr = new String[itemNames.size()];
stockArr = itemNames.toArray(stockArr);
dropDownList = new Combo(composite, SWT.NONE);
dropDownList.setItems(stockArr);
dropDownList.addModifyListener(listener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if(getShell().isDisposed() == false) {
if(dropDownList.getItems() != null) {
selection = dropDownList.getText();
}
}
}
});
applyDialogFont(composite);
dropDownList.setLayoutData(new GridData(GridData.FILL_BOTH));
return composite;
}
/** Returns selection. */
public String getSelection() {
return selection;
}
/** GUI for the DropDownDialog. */
private class DropdownDialogGUI extends Composite {
/** Default Constructor for GUI builder. */
DropdownDialogGUI(Composite parent, int style) {
super(parent, style);
FillLayout container = new FillLayout();
container.marginHeight = 4;
container.marginWidth = 4;
setLayout(container);
setLayoutData(new GridData(GridData.FILL_BOTH));
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safetycases.ui.utils;
import static org.fortiss.af3.safetycases.ui.utils.Utils.centerWizard;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.fortiss.af3.safetycases.ui.commands.SCElementIsImpacted;
import org.fortiss.tooling.base.ui.dialog.ElementTreeSingleSelectDialogGUI;
import org.fortiss.tooling.base.ui.dialog.IDialogEditSupport;
import org.fortiss.tooling.base.ui.dialog.MultiRootTreeContentProvider;
/**
* This class creates a wizard with 3 pages and is used in {@link SCElementIsImpacted}.
* Class can be copied somewhere else and adjusted to create more pages, but DON'T EDIT IT HERE.
*
* @author liana
*/
public class MultiPageWizard {
/** String with the type of predefined change (Add, Modify or Remove). */
private String preDefinedTypeOfChange = "NONE";
/** String containing the personalized type of change defined by the user. */
private String personalizedTypeOfChange = "";
/** Represents type of impact: Challenged, Actually Impacted or Potentially Impacted. */
private String typeOfMaintenanceCause = "";
/** This is a wizard containing three other WizardPages. */
public class CreateMultiPageWizard extends Wizard {
/**
* First page of the wizard where the impact is chose (CHALLENGED OR ACTUALLY/POTENTIALLY
* IMPACTED.
*/
private SelectImpactWizard page;
/** Page of the wizard where the references are selected. */
private SelectReferenceWizard page1;
/**
* Page of the wizard where the type of change is chose (predefined or personalized type of
* change).
*/
private TypeOfChangeWizard page2;
/** Constructor. */
public CreateMultiPageWizard(List<?> roots, Object selected,
ITreeContentProvider contentProvider, ILabelProvider labelProvider,
IDialogEditSupport edit) {
super();
page = new SelectImpactWizard();
page1 = new SelectReferenceWizard(roots, selected, contentProvider, labelProvider,
edit);
page2 = new TypeOfChangeWizard();
setNeedsProgressMonitor(true);
}
/** {@inheritDoc} */
@Override
public String getWindowTitle() {
return "Set as Impacted";
}
/** {@inheritDoc} */
@Override
public void addPages() {
addPage(page);
addPage(page1);
addPage(page2);
}
/** {@inheritDoc} */
@Override
public boolean performFinish() {
// close window
dispose();
return true;
}
/***/
public SelectImpactWizard getSelectImpactPage() {
return page;
}
/** */
public SelectReferenceWizard getSelectReferencePage() {
return page1;
}
/** */
public TypeOfChangeWizard getTypeOfChangePage() {
return page2;
}
/**
* This function will be overwritten in the class {@link SCElementIsImpacted}.
*
* @param element
* @return Object
*/
public boolean acceptElement(Object element) {
return false;
}
}
/** Class representing the second page of the wizard. */
public class SelectImpactWizard extends WizardPage {
/** Text for defining own Type of Change. */
private Text text;
/** */
private Composite container;
/** Drop-down list for predefined Type of Changes. */
private Combo dropDownList;
/** Listener for changes in the DropDownList. */
private ModifyListener listener;
/** Constructor. */
public SelectImpactWizard() {
super("SelectImpact");
setTitle("Change the maintenance cause of the argument element");
setDescription(
"You can set the maintenance cause of an argument element as Challenged, Actually Impacted or Potentially Impacted.");
setControl(text);
}
/** {@inheritDoc} */
@Override
public void createControl(Composite parent) {
if(getShell().isDisposed() == false && getShell().getDisplay().isDisposed() == false) {
getShell().setSize(530, 270);
centerWizard(getShell());
container = new Composite(parent, SWT.NONE);
FillLayout fillLayout = new FillLayout();
fillLayout.type = SWT.VERTICAL;
container.setLayout(fillLayout);
setPageComplete(false);
Label label1 = new Label(container, SWT.NONE);
label1.setText("Choose maintenance cause");
dropDownList = new Combo(container, SWT.NONE);
dropDownList.setItems(
new String[] {"Challenged", "Potentially Impacted", "Actually Impacted"});
dropDownList.setText("NONE");
dropDownList.addModifyListener(listener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if(getShell().isDisposed() == false) {
if(!dropDownList.getText().equals("NONE")) {
setPageComplete(true);
typeOfMaintenanceCause = dropDownList.getText();
} else if(text.getText().isEmpty()) {
setPageComplete(false);
}
}
}
});
// required to avoid an error in the system
setControl(container);
}
}
/** {@inheritDoc} */
@Override
public void dispose() {
super.dispose();
dropDownList.removeModifyListener(listener);
}
/** */
public String getText() {
return text.getText();
}
/** */
public Combo getDropDownList() {
return dropDownList;
}
/** */
public String getComboText() {
return dropDownList.getText();
}
}
/** Class representing the first page of the wizard. */
public class SelectReferenceWizard extends WizardPage {
/** */
private Composite container;
/** The GUI composite */
private ElementTreeSingleSelectDialogGUI gui;
/** The root elements. */
private ArrayList<Object> rootElements;
/** The selected element as tree path. */