Commit 26b1df4a authored by Johannes Eder's avatar Johannes Eder
Browse files

removed unused classes

Issue-Ref: 3886
Issue-Url: https://af3-developer.fortiss.org/issues/3886

Signed-off-by: Johannes Eder's avatarJohannes Eder <eder@fortiss.org>
parent e3430674
package org.fortiss.af3.mira.ui.utils;
import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
import java.util.List;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementsContainer;
import org.fortiss.af3.mira.model.RequirementsPackage;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
* Dialog to select a state.
*
* @author aravantinos
*/
public class ReqSelectionDialog extends TrayDialog {
/** Tree viewer containing the requirements. */
private TreeViewer dlgTreeViewer;
/** Selected requirement. */
public List<Requirement> selectedReqs = new ArrayList<Requirement>();
/** Containers from which to pick requirements. */
private List<RequirementsContainer> topContainers;
/** Constructor. */
public ReqSelectionDialog(Shell parentShell, RequirementsContainer topContainer) {
super(parentShell);
this.topContainers = new ArrayList<>();
this.topContainers.add(topContainer);
}
/** Constructor. */
public ReqSelectionDialog(Shell parentShell, List<RequirementsContainer> topContainers) {
super(parentShell);
this.topContainers = topContainers;
}
/** {@inheritDoc} */
@Override
protected Point getInitialSize() {
return new Point(1000, 600);
}
/** {@inheritDoc} */
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Pick a requirement");
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
PatternFilter filter = new PatternFilter();
FilteredTree tree =
new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
dlgTreeViewer = tree.getViewer();
dlgTreeViewer.setLabelProvider(new ModelElementLabelProvider());
dlgTreeViewer.setContentProvider(new TreeContentProviderBase() {
@Override
public Object[] getChildren(Object parentElement) {
if(parentElement instanceof List<?>) {
return ((List<?>)parentElement)
.toArray(new Object[((List<?>)parentElement).size()]);
}
if(parentElement instanceof RequirementsContainer ||
parentElement instanceof RequirementsPackage) {
EList<IHierarchicElement> elts =
((IHierarchicElement)parentElement).getContainedElements();
return elts.stream().filter(x -> isReq(x)).collect(toList()).toArray();
}
return new Object[0];
}
});
dlgTreeViewer.setAutoExpandLevel(3);
dlgTreeViewer.setInput(topContainers);
return parent;
}
/** True if shall be displayed in the tree. */
private boolean isReq(EObject x) {
return x instanceof Requirement || x instanceof RequirementsPackage ||
x instanceof RequirementsContainer;
}
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override
protected void okPressed() {
TreeSelection sel = (TreeSelection)dlgTreeViewer.getSelection();
selectedReqs = (List<Requirement>)sel.toList().stream()
.filter(r -> r instanceof Requirement).collect(toList());
super.okPressed();
}
}
/*-------------------------------------------------------------------------+
| Copyright 2012 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.mira.ui.utils;
import static org.conqat.lib.commons.filesystem.FileSystemUtils.copyFile;
import static org.eclipse.jface.dialogs.MessageDialog.openInformation;
import static org.fortiss.af3.project.ui.utils.NewProjectUtils.getDefaultGeneralProjectPath;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
/**
* Utility methods for the document files of requirement administration
*
* @author wenwenchen
*/
public class RequirementDocumentFileUtils {
/**
* Subfolder where all referenced documents are stored, relative to the general af3 project
* directory.
*/
public static final String PROJECT_DOCUMENT_SUBFOLDER = "Document";
/**
* Edit file link.
*
* @param composite
* the composite
* @return the input string
*/
public static String editFileLink(Composite composite) {
InputDialog networkFileInput = new InputDialog(composite.getShell(), "URL editor",
"Please enter a URL of the document", null, null);
networkFileInput.open();
String result = networkFileInput.getValue();
if(result != null && !result.trim().isEmpty()) {
// if(result.startsWith("http://") || result.startsWith("https://") ||
// result.startsWith("file://") || result.startsWith("ftp://"))
try {
return (new URL(result.trim())).toString();
} catch(MalformedURLException e) {
try {
return (new URL("http", result, "")).toString();
} catch(MalformedURLException e2) {
MessageDialog.openError(composite.getShell(), "Fehler input",
"Sorry, your input is unacceptable!");
return null;
}
}
}
return null;
}
/**
* Select local file.
*
* @param composite
* @return selected file, which is copied to the document folder of the project directory
*/
public static File selectLocalFile(Composite composite) {
String filepathStr = openDocumentFileDialog(composite.getShell());
if(filepathStr != null) {
Path filepath = new Path(filepathStr);
// the file will be copied to the document folder in the AF3
// Project directory
File sourceFile = new File(filepath.toOSString());
Path prjPath = new Path(getDefaultGeneralProjectPath());
File documentFolder = new File(prjPath.toOSString(), PROJECT_DOCUMENT_SUBFOLDER);
// create document directory if it does not exists
if(!documentFolder.exists() || !documentFolder.isDirectory())
documentFolder.mkdir();
// only the file named will be saved, the path is always the
// document folder
File destFile = new File(documentFolder, sourceFile.getName());
try {
if(!destFile.exists())
copyFile(sourceFile, destFile);
} catch(IOException ioe) {
openInformation(composite.getShell(), "Copy error",
"The file could not be copied into the project directory. ");
ioe.printStackTrace();
return null;
}
return destFile;
}
return null;
}
/**
* Opens a dialog to select an document file.
*
* @param shell
* @return the chosen file path or null if no file was selected
*/
public static String openDocumentFileDialog(Shell shell) {
FileDialog fileChooser = new FileDialog(shell, SWT.OPEN);
fileChooser.setText("Select document file");
// fileChooser.setFilterPath(currentDir);
fileChooser.setFilterExtensions(
new String[] {"*.pdf;*.doc;*.docx;*.txt;*.html;*.htm;*.gif;*.jpg;*.jpeg;*.png"});
fileChooser.setFilterNames(new String[] {
"Document file" + " (pdf, doc, docx, txt, html, htm, gif, jpg, jpeg, png)"});
return fileChooser.open();
}
}
/*-------------------------------------------------------------------------+
| Copyright 2011 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.mira.ui.utils;
import static java.util.Collections.sort;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.fortiss.af3.mira.utils.MiraUtils.getDisplayTypeFor;
import static org.fortiss.af3.mira.utils.MiraUtils.getRequirementComparator;
import static org.fortiss.af3.mira.utils.MiraUtils.getRequirementsContainerComparator;
import static org.fortiss.af3.mira.utils.MiraUtils.getRequirementsPackageComparator;
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 org.eclipse.emf.common.util.ECollections;
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.mira.command.ChangeRequirementRelationCommand;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementRelation;
import org.fortiss.af3.mira.model.RequirementsContainer;
import org.fortiss.af3.mira.model.RequirementsPackage;
import org.fortiss.af3.mira.ui.dialog.ElementTreeDoubleMultiSelectDialog;
import org.fortiss.af3.mira.ui.dialog.ElementTreeMultiSelectEditableDialog;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.dialog.ElementTreeSingleSelectDialog;
import org.fortiss.tooling.base.ui.dialog.ModelElementTreeContentProvider;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
* Utility class to let user select an {@link IModelElement} from
* {@link ElementTreeSingleSelectDialog}.
*
* @author uden
*/
public class SelectionDialogUtils {
/**
* Create a {@link ModelElementTreeContentProvider} for all containing {@link Requirement}s,
* {@link RequirementsContainer}s, and {@link RequirementsPackage}s.
*
* @param input
* Root element, which contains {@link Requirement}s.
* @return The created {@link ModelElementTreeContentProvider}.
*/
private static ModelElementTreeContentProvider
relatedRequirementsTreeContentProvider(List<? extends EObject> input) {
final List<Class<?>> acceptClassList = new ArrayList<Class<?>>();
acceptClassList.add(Requirement.class);
acceptClassList.add(RequirementsContainer.class);
acceptClassList.add(RequirementsPackage.class);
return new ModelElementTreeContentProvider(input) {
/** {@inheritDoc} */
@Override
public List<? extends EObject> getChildren(EObject parentElement) {
if(parentElement instanceof Analysis) {
List<IHierarchicElement> res = new ArrayList<IHierarchicElement>();
EList<IHierarchicElement> t = pickInstanceOf(acceptClassList,
((Analysis)parentElement).getContainedElements());
res.addAll(t);
Collections.sort(res, getRequirementsContainerComparator());
return res;
}
if(parentElement instanceof RequirementsContainer) {
EList<IHierarchicElement> t =
((RequirementsContainer)parentElement).getContainedElements();
ECollections.sort(t, getRequirementsPackageComparator());
return t;
}
if(parentElement instanceof RequirementsPackage) {
EList<IHierarchicElement> t =
((RequirementsPackage)parentElement).getContainedElements();
ECollections.sort(t, getRequirementsPackageComparator());
return t;
}
return Collections.emptyList();
}
};
}
/**
* Open source/target requirements dialog.
*
* @param shell
* The parent shell.
* @param relation
* The requirement relation.
* @param requirement
* A target/source of the given relation.
* @return Whether the dialog is open.
*/
public static boolean openSourceTargetRequirementsMultiSelectDialog(Shell shell,
final RequirementRelation relation, Requirement requirement) {
List<Analysis> root = Arrays.asList(relation.getAnalysis());
List<Requirement> oldSourceRequirementList =
new ArrayList<Requirement>(relation.getSourceRequirement());
List<Requirement> oldTargetRequirementList =
new ArrayList<Requirement>(relation.getTargetRequirement());
if(!oldSourceRequirementList.contains(requirement) &&
!oldTargetRequirementList.contains(requirement)) {
throw new IllegalArgumentException(
relation + " does not have the target requirement: " + requirement);
}
String title = "Select";
String message =
"Select source and target requirements via Drag & Drop. \nDouble-click to delete selected elements.";
ElementTreeDoubleMultiSelectDialog dialog =
new ElementTreeDoubleMultiSelectDialog(shell, root, oldSourceRequirementList,
oldTargetRequirementList, relatedRequirementsTreeContentProvider(root),
new ModelElementLabelProvider(), title, message) {
/** {@inheritDoc} */
@Override
public boolean acceptElement(Object element) {
return element instanceof Requirement;
}
};
if(Window.OK == dialog.open()) {
final List<Requirement> newSourceRequirementList = new ArrayList<Requirement>(
pickInstanceOf(Requirement.class, dialog.getMultiSelectedElements()));
final List<Requirement> newTargetRequirementList = new ArrayList<Requirement>(
pickInstanceOf(Requirement.class, dialog.getMultiSelectedElements2()));
if(newSourceRequirementList.contains(requirement) ||
newTargetRequirementList.contains(requirement) ||
openConfirmEditingRequirementRelationDialog(shell, requirement)) {
sort(newSourceRequirementList, getRequirementComparator());
sort(newTargetRequirementList, getRequirementComparator());
ICommandStackService.getInstance().runAsCommand(relation,
new ChangeRequirementRelationCommand(relation, newSourceRequirementList,
newTargetRequirementList));
return true;
}
}
return false;
}
/**
* Open a multi-select dialog and return selected target {@link Requirement}s.
*
* @param shell
* The parent shell.
* @param relation
* The requirement relation.
* @param requirement
* A target requirement of the given relation.
* @return A list of the actually selected {@link Requirement}s.
*/
public static List<Requirement> openTargetRequirementsMultiSelectDialog(Shell shell,
final RequirementRelation relation, Requirement requirement) {
List<Analysis> root = Arrays.asList(relation.getAnalysis());
final List<Requirement> oldTargetRequirementList =
new ArrayList<Requirement>(relation.getTargetRequirement());
if(!oldTargetRequirementList.contains(requirement)) {
throw new IllegalArgumentException(
relation + " does not have the target requirement: " + requirement);
}
String title = "Select";
String message =
"Select one or more elements via Drag & Drop or Double-click. \nDouble-click to delete selected elements.";
ElementTreeMultiSelectEditableDialog dialog = new ElementTreeMultiSelectEditableDialog(
shell, root, oldTargetRequirementList, relatedRequirementsTreeContentProvider(root),
new ModelElementLabelProvider(), null, title, message) {
/** {@inheritDoc} */
@Override
public boolean acceptElement(Object element) {
return element instanceof Requirement;
}
};
if(Window.OK == dialog.open()) {
if(dialog.getMultiSelectedElements().contains(requirement) ||
openConfirmEditingRequirementRelationDialog(shell, requirement)) {
final List<Requirement> newTargetRequirementList = new ArrayList<Requirement>(
pickInstanceOf(Requirement.class, dialog.getMultiSelectedElements()));
sort(newTargetRequirementList, getRequirementComparator());
ICommandStackService.getInstance().runAsCommand(relation,
new ChangeRequirementRelationCommand(relation, null,
newTargetRequirementList));
}
}
return relation.getTargetRequirement();
}
/**
* Open a confirm dialog for editing {@link RequirementRelation}, which contains the given
* {@link Requirement} any more.
*
* @param shell
* The parent shell.
* @param requirement
* The to-be-checked requirement.
* @return <code>true</code> if the user presses the OK button, <code>false</code> otherwise
*/
public static boolean openConfirmEditingRequirementRelationDialog(Shell shell,
Requirement requirement) {
return openConfirm(shell, "Confirm edit", "The edited " + getDisplayTypeFor(requirement) +
" is not a member of this edited relation any more, \n" +
"so this edited relation will not be listed hier. Do you confirm the edit?");
}
}
/*-------------------------------------------------------------------------+
| Copyright 2014 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.mira.ui.utils;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.widgets.TableColumn;
/**
* Utility methods for Table Columns.
*
* @author teufl
*/
public class TableColumnUtils {
/**
* TODO https://af3-developer.fortiss.org/issues/2273 (ST): Merge with TableViewerUtils in
* Tooling
* Creates a simple column in the table viewer.
*
* @param tableViewer
* the table viewer
* @param columnStyle
* the column style
* @param index
* the index at which to place the newly created column
* @param columnText
* the column text
* @param columnWidth
* the column width
* @param resizable
* is column resizable
* @return Table viewer {@link TableColumn}.
*/
public static TableColumn createColumn(final TableViewer tableViewer, int columnStyle,
int index, String columnText, int columnWidth, boolean resizable) {
TableViewerColumn columnViewer = new TableViewerColumn(tableViewer, columnStyle, index);
TableColumn column = columnViewer.getColumn();
column.setText(columnText);
column.setWidth(columnWidth);
column.setResizable(resizable);
return column;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment