diff options
17 files changed, 355 insertions, 134 deletions
diff --git a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/util/AtsXWidgetsExampleBlamTest.java b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/util/AtsXWidgetsExampleBlamTest.java index fa12a3466c3..5aaa21279fd 100644 --- a/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/util/AtsXWidgetsExampleBlamTest.java +++ b/plugins/org.eclipse.osee.ats.test/src/org/eclipse/osee/ats/util/AtsXWidgetsExampleBlamTest.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.osee.ats.util; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.osee.framework.logging.SevereLoggingMonitor; import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLoadOption; import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem; @@ -20,26 +22,29 @@ import org.eclipse.osee.framework.ui.skynet.blam.BlamContributionManager; import org.eclipse.osee.framework.ui.skynet.widgets.xnavigate.XNavigateItemBlam; import org.eclipse.osee.support.test.util.TestUtil; import org.junit.Assert; +import org.junit.Test; /** * @author Karol M. Wilk */ public class AtsXWidgetsExampleBlamTest { - private static final String NAME_OF_ATS_ITEM = "XWidgets Example"; + private static final String NAME_OF_ATS_ITEM = "XWidgets Example Blam"; /** * Load NAME_OF_ATS_ITEM blam, log any exceptions and report them as test failures. Purpose of this test is to serve * as a regression test to various widgets loaded in XWidgetExampleBlam. */ - @org.junit.Test + @Test public void testXWidgetsExampleBlam() throws Exception { SevereLoggingMonitor monitorLog = TestUtil.severeLoggingStart(); XNavigateItemBlam item = null; Collection<AbstractBlam> blams = BlamContributionManager.getBlamOperations(); + List<String> namesIveSeenSoFar = new ArrayList<String>(blams.size()); boolean foundBlam = false; for (AbstractBlam blam : blams) { + namesIveSeenSoFar.add(blam.getName()); if (blam.getName().equals(NAME_OF_ATS_ITEM)) { item = new XNavigateItemBlam(new XNavigateItem(null, "Blam Operations", FrameworkImage.BLAM), blam); foundBlam = true; diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java index 76851ba5a17..b6897ab7f12 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java @@ -85,9 +85,9 @@ public abstract class AbstractOperation implements IOperation { * All the operations work should be executed directly or indirectly by this method. The operation runs until its * doWork() method terminates normally or by throwing an exception (including OperationCanceledException) * - * @param subMonitor the progress monitor to use for reporting progress to the user. It is the caller's - * responsibility to call done() on the given monitor. Accepts null, indicating that no progress should be reported - * and that the operation cannot be cancelled. + * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility + * to call done() on the given monitor. Accepts null, indicating that no progress should be reported and that the + * operation cannot be cancelled. * @throws Exception the exception will be caught by the calling method and turned into a status */ protected abstract void doWork(IProgressMonitor monitor) throws Exception; diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ClientLogger.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ClientLogger.java new file mode 100644 index 00000000000..7bfd726dd97 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ClientLogger.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2011 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.framework.core.operation; + +import java.util.Arrays; +import java.util.logging.Level; +import org.eclipse.osee.framework.logging.OseeLevel; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Karol M. Wilk + * @author Ryan D. Brooks + */ +public class ClientLogger extends OperationLogger { + private final Class<?> activatorClass; + + public ClientLogger(Class<?> activatorClass) { + this.activatorClass = activatorClass; + } + + @Override + public void log(String... row) { + OseeLog.log(activatorClass, Level.INFO, Arrays.deepToString(row)); + } + + @Override + public void log(Throwable th) { + OseeLog.log(activatorClass, OseeLevel.SEVERE_POPUP, th); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java index 1a826b4ff97..38f54ad83e8 100644 --- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java +++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java @@ -107,19 +107,28 @@ public class Strings { } /** + * @param items items to be joined in a sentence, i.e. <code>{A, B, C, D}</code> + * @param joiningWord default joining word <code>" and "</code> + * @return <code>A, B, C joiningWord D</code> + */ + public static String buildStatment(List<?> items) { + return buildStatment(items, " and "); + } + + /** * Provides a nicer list of items with an 'and' at the end. This could be done using iterator(). * * @param items Lists of form { apple, banana, orange } or { apple, banana } * @return string of form "apple, banana and orange" or "apple and banana" depending on size of list */ - public static String buildStatment(List<?> items) { + public static String buildStatment(List<?> items, String joiningWord) { StringBuilder niceList = new StringBuilder(); if (items.size() >= 2) { int andIndex = items.size() - 2; for (int itemIndex = 0; itemIndex < items.size(); itemIndex++) { niceList.append(items.get(itemIndex)); if (itemIndex == andIndex) { - niceList.append(" and "); + niceList.append(joiningWord); } else if (itemIndex < andIndex) { niceList.append(", "); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ChangeArtifactType.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ChangeArtifactType.java index 9b3897ced63..354bce940dd 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ChangeArtifactType.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ChangeArtifactType.java @@ -180,7 +180,7 @@ public class ChangeArtifactType { answer = (MutableBoolean) value.getFirst(); Integer kindOfAnswer = (Integer) value.getSecond(); - userAnsweredYesToAll = kindOfAnswer == 1 && answer; + userAnsweredYesToAll = kindOfAnswer == 1 && answer.getValue(); } return answer == null ? false : answer.getValue(); } catch (Exception ex) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/FrameworkUi_Demo_Suite.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/FrameworkUi_Demo_Suite.java index c00c6633910..bbf4a74873f 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/FrameworkUi_Demo_Suite.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/FrameworkUi_Demo_Suite.java @@ -17,6 +17,7 @@ import org.eclipse.osee.framework.plugin.core.util.OseeData; import org.eclipse.osee.framework.ui.skynet.test.artifact.ArtifactPromptChangeTest; import org.eclipse.osee.framework.ui.skynet.test.blam.BlamXWidgetTest; import org.eclipse.osee.framework.ui.skynet.test.blam.operation.EmailGroupsBlamTest; +import org.eclipse.osee.framework.ui.skynet.test.blam.operation.StringGuidsToArtifactListOperationTest; import org.eclipse.osee.framework.ui.skynet.test.cases.ArtifactPasteConfigurationTest; import org.eclipse.osee.framework.ui.skynet.test.cases.ArtifactPasteOperationTest; import org.eclipse.osee.framework.ui.skynet.test.cases.AttributeTypeEditPresenterTest; @@ -30,11 +31,11 @@ import org.eclipse.osee.framework.ui.skynet.test.cases.WordEditTest; import org.eclipse.osee.framework.ui.skynet.test.cases.WordTrackedChangesTest; import org.eclipse.osee.framework.ui.skynet.test.dbHealth.RelationIntegrityCheckTest; import org.eclipse.osee.framework.ui.skynet.test.importer.ImportTestSuite; +import org.eclipse.osee.framework.ui.skynet.test.render.word.WordTestSuite; import org.eclipse.osee.framework.ui.skynet.test.renderer.RendererTestSuite; import org.eclipse.osee.framework.ui.skynet.test.renderer.imageDetection.WordImageCompareTest; import org.eclipse.osee.framework.ui.skynet.test.util.enumeration.AbstractEnumerationTest; import org.eclipse.osee.framework.ui.skynet.test.widgets.workflow.WorkPageAdapterTest; -import org.eclipse.osee.framework.ui.skynet.test.render.word.WordTestSuite; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; @@ -43,8 +44,9 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ WordImageCompareTest.class, -BlamXWidgetTest.class, + BlamXWidgetTest.class, EmailGroupsBlamTest.class, + StringGuidsToArtifactListOperationTest.class, ResultsEditorConverterTest.class, ArtifactPasteConfigurationTest.class, ArtifactPasteOperationTest.class, diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/blam/operation/StringGuidsToArtifactListOperationTest.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/blam/operation/StringGuidsToArtifactListOperationTest.java new file mode 100644 index 00000000000..dc2b207073b --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/blam/operation/StringGuidsToArtifactListOperationTest.java @@ -0,0 +1,122 @@ +package org.eclipse.osee.framework.ui.skynet.test.blam.operation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.core.operation.StringOperationLogger; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.eclipse.osee.framework.skynet.core.UserManager; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager; +import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; +import org.eclipse.osee.framework.skynet.core.httpRequests.PurgeBranchHttpRequestOperation; +import org.eclipse.osee.framework.ui.skynet.blam.operation.StringGuidsToArtifactListOperation; +import org.eclipse.osee.framework.ui.skynet.widgets.IXWidgetInputAddable; +import org.eclipse.osee.support.test.util.DemoSawBuilds; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * {@link StringGuidsToArtifactListOperation} + * + * @author Karol M. Wilk + */ +public class StringGuidsToArtifactListOperationTest { + + private static final String SAMPLE_SEPARATOR = "\r\n"; + private static final int capacity = 10; + private static Branch testBranch; + + private final static Collection<Object> artifacts = new ArrayList<Object>(capacity); + private final static String[] guids = new String[capacity]; + private final String invalidGuid = String.format("4F@3g@#$G@GZS%s", SAMPLE_SEPARATOR); + + @BeforeClass + public static void setUpOnce() throws OseeCoreException { + testBranch = + BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_1, + StringGuidsToArtifactListOperationTest.class.getSimpleName() + " Branch", + UserManager.getUser(SystemUser.OseeSystem)); + + for (int i = 0; i < capacity; ++i) { + Artifact artifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, testBranch, "Test" + i); + guids[i] = artifact.getGuid(); + artifact.persist("Save"); + artifacts.add(artifact); + } + } + + @AfterClass + public static void tearDownOnce() throws OseeCoreException { + Operations.executeWorkAndCheckStatus(new PurgeBranchHttpRequestOperation(testBranch, true)); + } + + @Test + public void test_doWork_findCreatedArtifacts() throws OseeCoreException { + Operations.executeWorkAndCheckStatus(new StringGuidsToArtifactListOperation(new StringOperationLogger(), + generateSampleClipboardContent(), testBranch, widgetMock_Equal)); + } + + @Test + public void test_doWork_guidGarbageData() throws OseeCoreException { + Operations.executeWorkAndCheckStatus(new StringGuidsToArtifactListOperation(new StringOperationLogger(), + generateGarbageClipboardContent(), testBranch, widgetMock_2Uniques)); + } + + @Test + public void test_doWork_nullClipboardData() throws OseeCoreException { + Operations.executeWorkAndCheckStatus(new StringGuidsToArtifactListOperation(new StringOperationLogger(), null, + testBranch, widgetMock_Equal)); + } + + private String generateGarbageClipboardContent() { + StringBuilder builder = new StringBuilder(guids.length); + builder.append(invalidGuid); + for (int i = 0; i < guids.length; i++) { + switch (i) { + case 1: + case 5: + //inject at some random places + builder.append(invalidGuid); + break; + default: + builder.append(String.format("%s%s", guids[i], SAMPLE_SEPARATOR)); + break; + } + } + return builder.toString(); + } + + private String generateSampleClipboardContent() { + StringBuilder builder = new StringBuilder(); + for (String guid : guids) { + builder.append(String.format("%s%s", guid, SAMPLE_SEPARATOR)); + } + return builder.toString(); + } + + private final IXWidgetInputAddable widgetMock_Equal = new IXWidgetInputAddable() { + @Override + public void addToInput(Collection<Object> objects) { + List<Object> uniques = Collections.setComplement(new HashSet<Object>(objects), new HashSet<Object>(artifacts)); + Assert.assertTrue(uniques.isEmpty()); + } + }; + + private final IXWidgetInputAddable widgetMock_2Uniques = new IXWidgetInputAddable() { + @Override + public void addToInput(Collection<Object> objects) { + List<Object> uniques = Collections.setComplement(new HashSet<Object>(artifacts), new HashSet<Object>(objects)); + Assert.assertTrue(uniques.size() == 2); //generateGarbageClipboardContent() takes out 1 and 5 + } + }; + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/AbstractBlam.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/AbstractBlam.java index 6b8068cba8e..da472483533 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/AbstractBlam.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/AbstractBlam.java @@ -54,7 +54,7 @@ public abstract class AbstractBlam implements IDynamicWidgetLayoutListener { private static final String DEFAULT_DESCRIPTION = "Select parameters below and click the play button at the top right."; - private final Pattern capitalLetter = Pattern.compile("[A-Z]{1}?[a-z]+"); + private final Pattern capitalLetter = Pattern.compile("[A-Z]+[a-z]*"); public enum BlamUiSource { DEFAULT, @@ -82,18 +82,14 @@ public abstract class AbstractBlam implements IDynamicWidgetLayoutListener { } private String generateNameFromClass() { - String className = getName(); - if (Strings.isValid(className) && className.indexOf(" ") == -1) { - StringBuilder generatedName = new StringBuilder(className.length() + 7); - - Matcher capMatch = capitalLetter.matcher(className); - for (boolean found = capMatch.find(); found || !capMatch.hitEnd(); found = capMatch.find()) { - generatedName.append(capMatch.start() > 0 ? " " + capMatch.group() : capMatch.group()); - } - return generatedName.toString(); - } else { - return className; + String className = getClass().getSimpleName(); + StringBuilder generatedName = new StringBuilder(className.length() + 7); + + Matcher capMatch = capitalLetter.matcher(className); + for (boolean found = capMatch.find(); found || !capMatch.hitEnd(); found = capMatch.find()) { + generatedName.append(capMatch.start() > 0 ? " " + capMatch.group() : capMatch.group()); } + return generatedName.toString(); } public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception { @@ -153,7 +149,7 @@ public abstract class AbstractBlam implements IDynamicWidgetLayoutListener { } public String getName() { - return Strings.isValid(this.name) ? this.name : getClass().getSimpleName(); + return name; } public void setOseeDatabaseService(IOseeDatabaseService service) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamContributionManager.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamContributionManager.java index 9779e1e97aa..320046e08cf 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamContributionManager.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamContributionManager.java @@ -103,7 +103,6 @@ public class BlamContributionManager implements IXNavigateCommonItem { } } catch (OseeCoreException ex) { OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex); - ; } } } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamEditorInput.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamEditorInput.java index 4499b4c8201..f98ecb36f17 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamEditorInput.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/BlamEditorInput.java @@ -22,6 +22,8 @@ import org.eclipse.ui.IPersistableElement; */ public class BlamEditorInput implements IEditorInput { + private final static String titleEnd = " BLAM"; + private final AbstractBlam blamOperation; public BlamEditorInput(AbstractBlam blamOperation) { @@ -38,7 +40,7 @@ public class BlamEditorInput implements IEditorInput { @Override public String getName() { - return blamOperation.getName() + " BLAM"; + return blamOperation.getName().toLowerCase().contains(titleEnd.toLowerCase().trim()) ? blamOperation.getName() : blamOperation.getName() + titleEnd; } public Image getImage() { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactTypeBlam.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactTypeBlam.java index f0ee01ceb4d..997a0000bd2 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactTypeBlam.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactTypeBlam.java @@ -13,40 +13,18 @@ package org.eclipse.osee.framework.ui.skynet.blam.operation; import java.util.Arrays; import java.util.Collection; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.jdk.core.util.GUID; -import org.eclipse.osee.framework.logging.OseeLevel; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.ChangeArtifactType; -import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; -import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam; import org.eclipse.osee.framework.ui.skynet.blam.VariableMap; -import org.eclipse.osee.framework.ui.skynet.widgets.XBranchSelectWidget; -import org.eclipse.osee.framework.ui.skynet.widgets.XListDropViewer; -import org.eclipse.osee.framework.ui.skynet.widgets.XModifiedListener; -import org.eclipse.osee.framework.ui.skynet.widgets.XWidget; -import org.eclipse.osee.framework.ui.skynet.widgets.workflow.DynamicXWidgetLayout; -import org.eclipse.osee.framework.ui.swt.Displays; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.forms.widgets.FormToolkit; /** * Changes the descriptor type of an artifact to the provided descriptor. * * @author Jeff C. Phillips + * @author Karol M. Wilk */ public class ChangeArtifactTypeBlam extends AbstractBlam { - private XListDropViewer artifactListWidget; - private XBranchSelectWidget branchWidget; - private static final String description = "Start by drag-and-drop or by pasting GUIDs of artifacts. Log what the previous type of each artifact was because that information is loss after running this blam"; @@ -61,55 +39,6 @@ public class ChangeArtifactTypeBlam extends AbstractBlam { } @Override - public void widgetCreating(XWidget xWidget, FormToolkit toolkit, Artifact art, DynamicXWidgetLayout dynamicXWidgetLayout, XModifiedListener modListener, boolean isEditable) { - String widgetLabel = xWidget.getLabel(); - - if (widgetLabel.equals("artifacts")) { - artifactListWidget = (XListDropViewer) xWidget; - } else if (widgetLabel.equals("Branch")) { - branchWidget = (XBranchSelectWidget) xWidget; - } - } - - @Override - public void widgetCreated(XWidget xWidget, FormToolkit toolkit, Artifact art, DynamicXWidgetLayout dynamicXWidgetLayout, XModifiedListener modListener, boolean isEditable) { - String widgetName = xWidget.getLabel(); - if (widgetName.equals("artifacts")) { - final Menu popupMenu = artifactListWidget.popupMenu(); - MenuItem paste = new MenuItem(popupMenu, SWT.NONE); - paste.setText("Paste GUIDs from Clipboard"); - paste.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - Displays.ensureInDisplayThread(new Runnable() { - @Override - public void run() { - final Clipboard cb = new Clipboard(popupMenu.getDisplay()); - TextTransfer transfer = TextTransfer.getInstance(); - String data = (String) cb.getContents(transfer); - - String[] guids = data.split("\t|\n|\r"); - for (String guid : guids) { - if (GUID.isValid(guid)) { - try { - Artifact artifact = ArtifactQuery.getArtifactFromId(guid, branchWidget.getSelection()); - artifactListWidget.addToInput(artifact); - } catch (Exception ex) { - OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); - } - } - } - } - }); - } - - }); - - } - } - - @Override public Collection<String> getCategories() { return Arrays.asList("Admin"); } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/StringGuidsToArtifactListOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/StringGuidsToArtifactListOperation.java new file mode 100644 index 00000000000..2bf7f045fda --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/StringGuidsToArtifactListOperation.java @@ -0,0 +1,89 @@ +package org.eclipse.osee.framework.ui.skynet.blam.operation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; +import org.eclipse.osee.framework.ui.skynet.widgets.IXWidgetInputAddable; + +/** + * Typically used to parse GUIDs copied from another application via text-clipboard. Operation extracts input from + * <code>guidData</code> argument and attempts to find artifacts referenced by GUIDs on argument branch. The result list + * of artifacts is then passed to IXWidgetInputAddable-type widget. + * + * @author Karol M. Wilk + */ +public class StringGuidsToArtifactListOperation extends AbstractOperation { + + private final String rawGuidsData; + private final Branch branch; + private final IXWidgetInputAddable widget; + + public final static String splitRegex = "\\s+"; + + private final static String taskName = "Mapping GUIDs to Artifacts..."; + private final static String subTaskName = "Retrieving Artifacts from cache and/or database..."; + + /** + * @param guidData string data of form <code>GUID1\\s+GUID2\\s+...GUIDN\\s+</code> separated by <code>\\s+</code> + * @param branch on which the artifacts live on + * @param widget accepting input by implementing <code>IXWidgetInputAddable</code> interface + */ + public StringGuidsToArtifactListOperation(OperationLogger logger, String guidData, Branch branch, IXWidgetInputAddable widget) { + super(taskName, SkynetGuiPlugin.PLUGIN_ID, logger); + this.rawGuidsData = guidData; + this.branch = branch; + this.widget = widget; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + if (Strings.isValid(rawGuidsData) && branch != null && widget != null) { + //Arbitrary number accounting for querying the cache and db retrieval + int costOfArtifactRetrieval = 5; + + String[] guids = this.rawGuidsData.split(splitRegex); + monitor.beginTask(taskName, guids.length + costOfArtifactRetrieval); + + List<String> validGuids = new ArrayList<String>(guids.length); + final Collection<Object> artifacts = new ArrayList<Object>(guids.length); //widget accepts Collection<Object> + + for (int guidIndex = 0; !monitor.isCanceled() && guidIndex < guids.length; guidIndex++) { + if (GUID.isValid(guids[guidIndex])) { + validGuids.add(guids[guidIndex]); + } + monitor.worked(guidIndex + 1); + } + + try { + //written to minimize calls to db VS individuals gets (+cost of overhead) + if (!monitor.isCanceled()) { + monitor.subTask(subTaskName); + monitor.beginTask(subTaskName, costOfArtifactRetrieval); + artifacts.addAll(ArtifactQuery.getArtifactListFromIds(validGuids, this.branch)); + monitor.done(); + monitor.worked(costOfArtifactRetrieval); + } + } catch (Exception ex) { + getLogger().log(ex); + } + + monitor.done(); + + widget.addToInput(artifacts); + } else { + getLogger().logf("Problem with arguments for this operation: %s", + Strings.buildStatment(Arrays.asList(new String[] {"rawGuidsData", "branch", "widget"})), " or "); + monitor.setCanceled(true); + monitor.done(); + } + } +} diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/XWidgetsExampleBlam.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/XWidgetsExampleBlam.java index 6c21b5e58f6..3d9f2b58561 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/XWidgetsExampleBlam.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/XWidgetsExampleBlam.java @@ -13,8 +13,6 @@ package org.eclipse.osee.framework.ui.skynet.blam.operation; import java.util.Arrays; import java.util.Collection; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam; import org.eclipse.osee.framework.ui.skynet.blam.VariableMap; @@ -23,9 +21,12 @@ import org.eclipse.osee.framework.ui.skynet.blam.VariableMap; * @author Karol M Wilk */ public class XWidgetsExampleBlam extends AbstractBlam { - @Override - public String getName() { - return "XWidgets Example"; + + private static final String description = + "This BLAM provides an example of all available XWidgets for use by developers of BLAMs and other UIs"; + + public XWidgetsExampleBlam() { + super(null, description, BlamUiSource.FILE); } @Override @@ -37,14 +38,4 @@ public class XWidgetsExampleBlam extends AbstractBlam { public Collection<String> getCategories() { return Arrays.asList("Util"); } - - @Override - public String getXWidgetsXml() throws OseeCoreException { - return getXWidgetsXmlFromUiFile(getName(), SkynetGuiPlugin.PLUGIN_ID); - } - - @Override - public String getDescriptionUsage() { - return "This BLAM provides an example of all available XWidgets for use by developers of BLAMs and other UIs"; - } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/IXWidgetInputAddable.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/IXWidgetInputAddable.java new file mode 100644 index 00000000000..17879cf5cbd --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/IXWidgetInputAddable.java @@ -0,0 +1,7 @@ +package org.eclipse.osee.framework.ui.skynet.widgets; + +import java.util.Collection; + +public interface IXWidgetInputAddable { + public void addToInput(Collection<Object> objects); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListDropViewer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListDropViewer.java index db8bf6bc9e0..df0fba41368 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListDropViewer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListDropViewer.java @@ -16,13 +16,22 @@ import java.util.Iterator; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.ClientLogger; +import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.ui.skynet.ArtifactLabelProvider; +import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; import org.eclipse.osee.framework.ui.skynet.artifact.ArtifactTransfer; +import org.eclipse.osee.framework.ui.skynet.blam.operation.StringGuidsToArtifactListOperation; +import org.eclipse.osee.framework.ui.skynet.branch.BranchSelectionDialog; import org.eclipse.osee.framework.ui.skynet.util.SkynetDragAndDrop; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; @@ -32,7 +41,7 @@ import org.eclipse.swt.widgets.MenuItem; /** * @author Ryan D. Brooks */ -public class XListDropViewer extends XListViewer { +public class XListDropViewer extends XListViewer implements IXWidgetInputAddable { private MenuItem removeFromMenuItem; private TableViewer myTableViewer; private ArrayContentProvider myArrayContentProvider = null; @@ -56,7 +65,6 @@ public class XListDropViewer extends XListViewer { super.createControls(parent, horizontalSpan); new XDragAndDrop(); this.myTableViewer = super.getTableViewer(); - // popupMenu.addMenuListener(new MenuEnablingListener()); createRemoveFromMenuItem(popupMenu); myTableViewer.getTable().setMenu(popupMenu); } @@ -83,10 +91,32 @@ public class XListDropViewer extends XListViewer { } }); - } - public Menu popupMenu() { - return popupMenu; + MenuItem paste = new MenuItem(popupMenu, SWT.NONE); + paste.setText("Paste GUIDs from Clipboard"); + paste.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Displays.ensureInDisplayThread(new Runnable() { + + @Override + public void run() { + Clipboard cb = new Clipboard(popupMenu.getDisplay()); + try { + TextTransfer transfer = TextTransfer.getInstance(); + String data = (String) cb.getContents(transfer); + Branch branch = BranchSelectionDialog.getBranchFromUser(); + Operations.executeAsJob(new StringGuidsToArtifactListOperation(new ClientLogger( + SkynetGuiPlugin.class), data, branch, XListDropViewer.this), true); + } finally { + cb.dispose(); + } + } + }); + + } + }); } /** @@ -99,13 +129,25 @@ public class XListDropViewer extends XListViewer { objects.add(artifact); } - if (getInput() == null) { - setInput(objects); - } else { - add(objects); - updateListWidget(); + addToInput(objects); + } + + @Override + public void addToInput(final Collection<Object> objects) { + if (!objects.isEmpty()) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + if (getInput() == null) { + setInput(objects); + } else { + add(objects); + updateListWidget(); + } + notifyXModifiedListeners(); + } + }); } - notifyXModifiedListeners(); } @Override @@ -126,11 +168,6 @@ public class XListDropViewer extends XListViewer { } @Override - public void performTextDrop(String text) { - System.out.println("You dragged: " + text); - } - - @Override public Artifact[] getArtifacts() { return null; } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListViewer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListViewer.java index 5d542d1e262..70442e68e9a 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListViewer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XListViewer.java @@ -275,12 +275,8 @@ public class XListViewer extends GenericXWidget { } public void add(Collection<Object> objects) { - // to ensure no duplicates input.removeAll(objects); - - if (!input.containsAll(objects)) { - input.addAll(objects); - } + input.addAll(objects); } public void setSelected(ArrayList<Object> selected) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/ui/ChangeArtifactTypeBlamUi.xml b/plugins/org.eclipse.osee.framework.ui.skynet/ui/ChangeArtifactTypeBlamUi.xml index 550a8db3b67..bc52e28d287 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/ui/ChangeArtifactTypeBlamUi.xml +++ b/plugins/org.eclipse.osee.framework.ui.skynet/ui/ChangeArtifactTypeBlamUi.xml @@ -1,5 +1,4 @@ <xWidgets> - <XWidget xwidgetType="XBranchSelectWidget" displayName="Branch" /> <XWidget xwidgetType="XListDropViewer" displayName="artifacts" /> <XWidget xwidgetType="XArtifactTypeComboViewer" displayName="New Artifact Type" /> </xWidgets> |