Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2012-01-30 17:01:41 +0000
committerRyan D. Brooks2012-01-30 17:01:41 +0000
commit2032d716277771423f4a7fd4f9383c9edd422bde (patch)
tree4bcfe0a6a61048d439687214bced46052de25f52
parent18c2c64a8eda4b9b77b3fdee02dbbb6dcc203912 (diff)
downloadorg.eclipse.osee-2032d716277771423f4a7fd4f9383c9edd422bde.tar.gz
org.eclipse.osee-2032d716277771423f4a7fd4f9383c9edd422bde.tar.xz
org.eclipse.osee-2032d716277771423f4a7fd4f9383c9edd422bde.zip
feature[ats_AGHDK]: Add dialog before renaming test cases0.9.9.v201201310003_SR4
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceResourceDropOperation.java38
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/UiRenameConfirmer.java188
2 files changed, 221 insertions, 5 deletions
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceResourceDropOperation.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceResourceDropOperation.java
index e6ed4a107af..23ef2efe8dd 100644
--- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceResourceDropOperation.java
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceResourceDropOperation.java
@@ -14,6 +14,9 @@ import java.io.File;
import java.net.URI;
import java.nio.CharBuffer;
import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -39,19 +42,26 @@ import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
*/
public class TraceResourceDropOperation extends AbstractOperation {
+ public static interface RenameConfirmer {
+
+ boolean acceptUpdate(Map<Artifact, String> nameUpdateRequired);
+ }
+
private final Collection<URI> resources;
private final IResourceLocator locator;
private final IRelationTypeSide relTypeSide;
private final Artifact requirement;
private final boolean persistChanges;
+ private final RenameConfirmer confirmer;
- public TraceResourceDropOperation(Collection<URI> resources, IRelationTypeSide relTypeSide, Artifact requirement, IResourceLocator locator, boolean persistChanges) {
+ public TraceResourceDropOperation(Collection<URI> resources, IRelationTypeSide relTypeSide, Artifact requirement, IResourceLocator locator, boolean persistChanges, RenameConfirmer confirmer) {
super("Trace Resource Drop Operation", Activator.PLUGIN_ID);
this.relTypeSide = relTypeSide;
this.requirement = requirement;
this.resources = resources;
this.locator = locator;
this.persistChanges = persistChanges;
+ this.confirmer = confirmer;
}
@Override
@@ -62,20 +72,37 @@ public class TraceResourceDropOperation extends AbstractOperation {
if (persistChanges) {
transaction = TransactionManager.createTransaction(branch, "TraceResourceDrop");
}
+
+ Map<Artifact, String> nameUpdateRequired = new TreeMap<Artifact, String>();
+
for (URI resource : resources) {
File file = new File(resource);
if (!file.isDirectory()) {
- processFile(file, transaction);
+ processFile(file, transaction, nameUpdateRequired);
}
}
- if (persistChanges) {
+
+ boolean isOk = true;
+ if (!nameUpdateRequired.isEmpty()) {
+ if (confirmer != null) {
+ isOk = confirmer.acceptUpdate(nameUpdateRequired);
+ }
+
+ if (isOk) {
+ for (Entry<Artifact, String> entry : nameUpdateRequired.entrySet()) {
+ entry.getKey().setName(entry.getValue());
+ }
+ }
+ }
+
+ if (persistChanges && isOk) {
requirement.persist(transaction);
transaction.execute();
}
}
}
- private void processFile(File file, SkynetTransaction transaction) throws Exception {
+ private void processFile(File file, SkynetTransaction transaction, Map<Artifact, String> nameUpdateRequired) throws Exception {
CharBuffer fileBuffer = Lib.fileToCharBuffer(file);
IFileStore fileStore = EFS.getStore(file.toURI());
String name = locator.getIdentifier(fileStore, fileBuffer).getName();
@@ -104,8 +131,9 @@ public class TraceResourceDropOperation extends AbstractOperation {
tagger.addSourceTag(file.toURI(), testUnitArtifact.getGuid());
}
}
+
if (!testUnitArtifact.getName().equals(name)) {
- testUnitArtifact.setName(name);
+ nameUpdateRequired.put(testUnitArtifact, name);
}
requirement.addRelation(relTypeSide, testUnitArtifact);
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/UiRenameConfirmer.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/UiRenameConfirmer.java
new file mode 100644
index 00000000000..5e94d8b1dde
--- /dev/null
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/UiRenameConfirmer.java
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.define.traceability.operations;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.window.Window;
+import org.eclipse.nebula.widgets.xviewer.XViewer;
+import org.eclipse.nebula.widgets.xviewer.XViewerColumn;
+import org.eclipse.nebula.widgets.xviewer.XViewerColumn.SortDataType;
+import org.eclipse.nebula.widgets.xviewer.XViewerFactory;
+import org.eclipse.nebula.widgets.xviewer.XViewerLabelProvider;
+import org.eclipse.osee.define.internal.Activator;
+import org.eclipse.osee.define.traceability.operations.TraceResourceDropOperation.RenameConfirmer;
+import org.eclipse.osee.framework.jdk.core.type.MutableBoolean;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.ui.plugin.util.ArrayTreeContentProvider;
+import org.eclipse.osee.framework.ui.swt.Displays;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class UiRenameConfirmer implements RenameConfirmer {
+
+ @Override
+ public boolean acceptUpdate(final Map<Artifact, String> nameUpdateRequired) {
+ final MutableBoolean result = new MutableBoolean(false);
+ if (nameUpdateRequired != null && !nameUpdateRequired.isEmpty()) {
+ Displays.ensureInDisplayThread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ MessageDialog dialog = createDialog(nameUpdateRequired);
+ int value = dialog.open();
+ result.setValue(value == Window.OK);
+ } catch (Throwable ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Error during UI rename", ex);
+ result.setValue(false);
+ }
+ }
+ }, true);
+ } else {
+ result.setValue(true);
+ }
+ return result.getValue();
+ }
+
+ private MessageDialog createDialog(final Map<Artifact, String> nameUpdateRequired) {
+ MessageDialog dialog =
+ new XTableDialog(Displays.getActiveShell(), "Rename Artifacts", null,
+ "The following artifacts will be renamed.\n Select OK to continue with rename or Cancel to abort.",
+ MessageDialog.CONFIRM, new String[] {"Ok", "Cancel"}, 0, nameUpdateRequired);
+ return dialog;
+ }
+
+ private static final class XTableDialog extends MessageDialog {
+
+ private final Map<Artifact, String> nameUpdateRequired;
+
+ public XTableDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, Map<Artifact, String> nameUpdateRequired) {
+ super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels,
+ defaultIndex);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.nameUpdateRequired = nameUpdateRequired;
+ }
+
+ @Override
+ protected Control createCustomArea(Composite parent) {
+ Composite area = new Composite(parent, SWT.BORDER);
+ area.setLayout(new GridLayout());
+ area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ XTable table = new XTable(area, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ table.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table.setContentProvider(new XTableContentProvider());
+ table.setLabelProvider(new XTableLabelProvider(table));
+ table.setInput(nameUpdateRequired);
+ return area;
+ }
+ }
+
+ private static final class XTable extends XViewer {
+ public XTable(Composite parent, int style) {
+ super(parent, style, new XTableFactory());
+ }
+ }
+
+ private static final class XTableFactory extends XViewerFactory {
+ private static String COLUMN_NAMESPACE = "xviewer.rename.dialog.table";
+
+ public static XViewerColumn FROM_NAME_COLUMN = new XViewerColumn(COLUMN_NAMESPACE + ".from.name", "From Name",
+ 200, SWT.LEFT, true, SortDataType.String, false, null);
+ public static XViewerColumn TO_NAME_COLUMN = new XViewerColumn(COLUMN_NAMESPACE + ".to.name", "To Name", 200,
+ SWT.LEFT, true, SortDataType.String, false, null);
+
+ public XTableFactory() {
+ super(COLUMN_NAMESPACE);
+
+ registerColumns(FROM_NAME_COLUMN, TO_NAME_COLUMN);
+ }
+
+ @Override
+ public boolean isAdmin() {
+ return false;
+ }
+ }
+
+ private static final class XTableLabelProvider extends XViewerLabelProvider {
+
+ public XTableLabelProvider(XViewer xViewer) {
+ super(xViewer);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public String getColumnText(Object element, XViewerColumn xCol, int columnIndex) {
+ Entry<Artifact, String> item = ((Entry<Artifact, String>) element);
+ if (xCol.equals(XTableFactory.FROM_NAME_COLUMN)) {
+ return item.getKey().getSafeName();
+ }
+ if (xCol.equals(XTableFactory.TO_NAME_COLUMN)) {
+ return item.getValue();
+ }
+ return "unhandled column";
+ }
+
+ @Override
+ public void dispose() {
+ //
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ //
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ //
+ }
+
+ @Override
+ public Image getColumnImage(Object element, XViewerColumn xCol, int columnIndex) {
+ return null;
+ }
+ }
+
+ public static final class XTableContentProvider extends ArrayTreeContentProvider {
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Map) {
+ return ((Map<?, ?>) parentElement).entrySet().toArray();
+ } else if (parentElement instanceof Entry) {
+ Entry<?, ?> entry = ((Entry<?, ?>) parentElement);
+ return new Object[] {entry.getKey(), entry.getValue()};
+ }
+ return new Object[] {};
+ }
+
+ }
+
+}

Back to the top