Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.ui.skynet')
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/images/link.gifbin0 -> 218 bytes
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml3
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FrameworkImage.java1
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/AddNewLinkNavigateItem.java37
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinkDialog.java176
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinksNavigateItem.java175
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/FileChangedListener.java18
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinkUtil.java196
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinksNavigateViewItems.java246
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/util/FrameworkEvents.java26
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/dialog/EntryCheckDialog.java2
12 files changed, 880 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF
index 286586f222d..617f1de9835 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF
@@ -221,6 +221,7 @@ Export-Package: org.eclipse.osee.framework.ui.skynet,
org.eclipse.osee.framework.ui.skynet.group,
org.eclipse.osee.framework.ui.skynet.handler,
org.eclipse.osee.framework.ui.skynet.internal,
+ org.eclipse.osee.framework.ui.skynet.links,
org.eclipse.osee.framework.ui.skynet.listener,
org.eclipse.osee.framework.ui.skynet.menu,
org.eclipse.osee.framework.ui.skynet.mergeWizard,
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/images/link.gif b/plugins/org.eclipse.osee.framework.ui.skynet/images/link.gif
new file mode 100644
index 00000000000..5fd9c94946c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/images/link.gif
Binary files differ
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
index 608751e3556..63af1ba1349 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
@@ -1470,6 +1470,9 @@
<XCommonNavigateItem
classname="org.eclipse.osee.framework.ui.skynet.user.perspective.UserNavigateViewItems">
</XCommonNavigateItem>
+ <XCommonNavigateItem
+ classname="org.eclipse.osee.framework.ui.skynet.links.LinksNavigateViewItems">
+ </XCommonNavigateItem>
</extension>
<extension
point="org.eclipse.ui.perspectives">
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FrameworkImage.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FrameworkImage.java
index cc06eb44e78..91256d6a937 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FrameworkImage.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FrameworkImage.java
@@ -120,6 +120,7 @@ public enum FrameworkImage implements KeyedImage {
LEFT_ARROW_1("leftarrow1.png"),
LEFT_ARROW_N("leftarrowN.png"),
LINE_MATCH("line_match.gif"),
+ LINK("link.gif"),
LOAD("load.gif"),
LOCKED("lock.gif"),
LOCK_LOCKED("lock_locked.gif"),
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/AddNewLinkNavigateItem.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/AddNewLinkNavigateItem.java
new file mode 100644
index 00000000000..0d6ec4d8f9b
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/AddNewLinkNavigateItem.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+import org.eclipse.jface.window.Window;
+import org.eclipse.osee.account.rest.model.Link;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLoadOption;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem;
+import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class AddNewLinkNavigateItem extends XNavigateItem {
+
+ public AddNewLinkNavigateItem(XNavigateItem parent) {
+ super(parent, "Add New Link", FrameworkImage.GREEN_PLUS);
+ }
+
+ @Override
+ public void run(TableLoadOption... tableLoadOptions) throws Exception {
+ EditLinkDialog dialog = new EditLinkDialog();
+ if (dialog.open() == Window.OK) {
+ Link link = new Link();
+ LinkUtil.upateLinkFromDialog(dialog, link);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinkDialog.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinkDialog.java
new file mode 100644
index 00000000000..7ef9966ca9e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinkDialog.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+import org.eclipse.osee.account.rest.model.Link;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.ui.skynet.widgets.XText;
+import org.eclipse.osee.framework.ui.skynet.widgets.dialog.EntryCheckDialog;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Listener;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class EditLinkDialog extends EntryCheckDialog {
+
+ private XText urlTextWidget, tagTextWidget;
+ private String nameText, urlText = "", tagText = "";
+ private final String label2;
+ private Listener okListener;
+ private Link link;
+
+ public EditLinkDialog(Link link) {
+ this();
+ this.link = link;
+ urlText = link.getUrl();
+ tagText = Collections.toString(", ", link.getTags());
+ nameText = link.getName();
+ setEntry(nameText);
+ }
+
+ public EditLinkDialog() {
+ super("Enter Link", "Create/Update New Link", "Share with others");
+ super.setLabel("Link Name");
+ super.setTextHeight(100);
+ this.label2 = "URL";
+ }
+
+ @Override
+ protected void createExtendedArea(Composite parent) {
+ text.getLabelWidget().addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (e.button == 3) {
+ text.setText("Google");
+ urlTextWidget.setText("http://www.google.com");
+ tagTextWidget.setText("Search");
+ }
+ }
+
+ });
+
+ urlTextWidget = new XText(label2);
+ urlTextWidget.setFillHorizontally(true);
+ if (isFillVertically()) {
+ urlTextWidget.setFillVertically(true);
+ urlTextWidget.setHeight(100);
+ text.setHeight(100);
+ urlTextWidget.setFont(getFont());
+ }
+ urlTextWidget.set(urlText);
+ urlTextWidget.createWidgets(parent, 1);
+
+ urlTextWidget.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ handleModified();
+ urlText = urlTextWidget.get();
+ }
+ });
+
+ tagTextWidget = new XText("Enter Search Tags");
+ tagTextWidget.setFillHorizontally(true);
+ if (isFillVertically()) {
+ tagTextWidget.setFillVertically(true);
+ tagTextWidget.setHeight(100);
+ text.setHeight(100);
+ tagTextWidget.setFont(getFont());
+ }
+ tagTextWidget.set(tagText);
+ tagTextWidget.createWidgets(parent, 1);
+
+ tagTextWidget.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ handleModified();
+ tagText = tagTextWidget.get();
+ }
+ });
+
+ super.createExtendedArea(parent);
+ }
+
+ public String getUrl() {
+ return urlText;
+ }
+
+ public String getTags() {
+ return tagText;
+ }
+
+ public void setUrl(String url) {
+ if (urlTextWidget != null) {
+ urlTextWidget.set(url);
+ }
+ this.urlText = url;
+ }
+
+ public void setTags(String tags) {
+ if (urlTextWidget != null) {
+ urlTextWidget.set(tags);
+ }
+ this.urlText = tags;
+ }
+
+ public void setOkListener(Listener okListener) {
+ this.okListener = okListener;
+ }
+
+ @Override
+ protected void buttonPressed(int buttonId) {
+ super.buttonPressed(buttonId);
+ if (buttonId == 0 && okListener != null) {
+ okListener.handleEvent(null);
+ }
+ }
+
+ @Override
+ public boolean isEntryValid() {
+ if (!super.isEntryValid()) {
+ return false;
+ }
+ if (!Strings.isValid(getEntry())) {
+ setErrorString("Enter Link Name");
+ return false;
+ }
+ if (!Strings.isValid(getUrl())) {
+ setErrorString("Must Enter URL");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected Control createButtonBar(Composite parent) {
+ Control control = super.createButtonBar(parent);
+ handleModified();
+ return control;
+ }
+
+ public Link getLink() {
+ return link;
+ }
+
+ public void setLink(Link link) {
+ this.link = link;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinksNavigateItem.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinksNavigateItem.java
new file mode 100644
index 00000000000..7241d87d07c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/EditLinksNavigateItem.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osee.account.rest.model.AccountWebPreferences;
+import org.eclipse.osee.account.rest.model.Link;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.plugin.core.util.Jobs;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLoadOption;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem;
+import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
+import org.eclipse.osee.framework.ui.skynet.internal.Activator;
+import org.eclipse.swt.program.Program;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class EditLinksNavigateItem extends XNavigateItem implements FileChangedListener {
+
+ private static String LINKS_FILENAME = "OSSE_%s_Links.txt";
+ private static final List<FileChangedListener> listeners = new LinkedList<>();
+ private final boolean global;
+ private boolean addedListener = false;
+
+ public EditLinksNavigateItem(XNavigateItem parent, boolean global) {
+ super(parent, "Edit " + (global ? "Global" : "Personal") + " Links", FrameworkImage.EDIT);
+ this.global = global;
+ }
+
+ @Override
+ public void run(TableLoadOption... tableLoadOptions) throws Exception {
+ AccountWebPreferences webPrefs =
+ LinkUtil.getAccountsPreferencesData(LinkUtil.getStoreArtifact(global).getArtId());
+
+ StringBuilder sb = new StringBuilder(
+ "OSEE " + (global ? "Global" : "Personal") + " Links " + UserManager.getUser().toStringWithId() + "\n\n");
+ sb.append("// Move items up and down to change order.\n// Change names, urls and tags without changing id.\n// " //
+ + "Delete line to remove.\n// Copy existing link and clear id for new link.\n// Save to Update\n" //
+ + "// Example: {\"name\":\"Google\",\"url\":\"http://www.google.com\",\"id\":\"AOd9poc8Kz02K3K7xfwA\",\"team\":\"Joe Smith\",\"tags\":[]}\n\n");
+ ObjectMapper mapper = new ObjectMapper();
+ for (Link link : webPrefs.getLinks().values()) {
+ sb.append(mapper.writeValueAsString(link) + "\n");
+ }
+ File outFile = getLinksFile();
+ Lib.writeStringToFile(sb.toString(), outFile);
+ Program.launch(outFile.getAbsolutePath());
+
+ if (!addedListener) {
+ listeners.add(this);
+ addedListener = true;
+ }
+ startFileWatcher();
+ }
+
+ private File getLinksFile() {
+ File outFile = new File(System.getProperty("user.home") + "/" + getFilename(global));
+ return outFile;
+ }
+
+ private String getFilename(boolean global) {
+ return String.format(LINKS_FILENAME, (global ? "Global" : "Personal"));
+ }
+
+ private static final AtomicBoolean startedWatcher = new AtomicBoolean(false);
+
+ private static void startFileWatcher() {
+ if (startedWatcher.get()) {
+ return;
+ }
+ startedWatcher.set(true);
+
+ Job job = new Job("Links File Watcher") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ final Path dir = new File(System.getProperty("user.home")).toPath();
+ final WatchService watcher = FileSystems.getDefault().newWatchService();
+
+ WatchKey key = dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
+ for (;;) {
+
+ // pend for change to the home directory
+ try {
+ key = watcher.take();
+ } catch (InterruptedException ex) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, ex.getLocalizedMessage(), ex);
+ }
+
+ for (WatchEvent<?> event : key.pollEvents()) {
+
+ @SuppressWarnings("unchecked")
+ WatchEvent<Path> ev = (WatchEvent<Path>) event;
+ Path filename = ev.context();
+
+ for (FileChangedListener listener : listeners) {
+ listener.fileChanged(filename.toString());
+ }
+ }
+
+ // Reset the key
+ boolean valid = key.reset();
+ if (!valid) {
+ break;
+ }
+ }
+ return Status.OK_STATUS;
+ } catch (IOException ex) {
+ OseeLog.log(EditLinksNavigateItem.class, Level.SEVERE, ex);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, ex.getLocalizedMessage(), ex);
+ }
+ }
+ };
+ Jobs.startJob(job);
+ }
+
+ @Override
+ public void fileChanged(String filename) {
+ if (filename.endsWith(getFilename(global))) {
+ System.err.println("file changed: " + getFilename(global));
+ storeChangeAndContinue();
+ }
+ }
+
+ private void storeChangeAndContinue() {
+ try {
+ File outFile = getLinksFile();
+ String fileToString = Lib.fileToString(outFile);
+ ObjectMapper mapper = new ObjectMapper();
+ AccountWebPreferences newWebPrefs = new AccountWebPreferences();
+ for (String line : fileToString.split("\n")) {
+ if (line.startsWith("{")) {
+ Link link = mapper.readValue(line, Link.class);
+ newWebPrefs.getLinks().put(link.getId(), link);
+ }
+ }
+ Artifact useArtifact = LinkUtil.getStoreArtifact(global);
+ Conditions.checkNotNull(useArtifact,
+ "Could not find " + (global ? "Global" : "Personal") + " store artifact.");
+ LinkUtil.saveWebPreferences(newWebPrefs, global, useArtifact);
+ } catch (Exception ex) {
+ OseeLog.log(EditLinksNavigateItem.class, Level.SEVERE, ex);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/FileChangedListener.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/FileChangedListener.java
new file mode 100644
index 00000000000..035c339c23c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/FileChangedListener.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+/**
+ * @author Donald G. Dunne
+ */
+public interface FileChangedListener {
+ public void fileChanged(String filename);
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinkUtil.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinkUtil.java
new file mode 100644
index 00000000000..974817bea6d
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinkUtil.java
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.eclipse.osee.account.rest.client.AccountClient;
+import org.eclipse.osee.account.rest.model.AccountWebPreferences;
+import org.eclipse.osee.account.rest.model.Link;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.enums.SystemUser;
+import org.eclipse.osee.framework.core.event.EventType;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.skynet.core.User;
+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.search.ArtifactQuery;
+import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
+import org.eclipse.osee.framework.skynet.core.event.model.TopicEvent;
+import org.eclipse.osee.framework.ui.skynet.internal.ServiceUtil;
+import org.eclipse.osee.framework.ui.skynet.util.FrameworkEvents;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class LinkUtil {
+
+ private LinkUtil() {
+ // Utility class
+ }
+
+ public static AccountWebPreferences getAccountsPreferencesData(boolean global) throws Exception {
+ return getAccountsPreferencesData(getStoreArtifact(global).getArtId());
+ }
+
+ public static AccountWebPreferences getAccountsPreferencesData(int accountId) throws Exception {
+ AccountClient client = ServiceUtil.getAccountClient();
+ return client.getAccountWebPreferencesByUniqueField(Long.valueOf(accountId));
+ }
+
+ /**
+ * Delete single link from user or global links and store
+ */
+ public static void deleteLink(String accountId, Link deleteLink) throws Exception {
+ Artifact golbalArtifact = getStoreArtifact(true);
+ Conditions.checkNotNull(golbalArtifact, "Guest accountId: " + SystemUser.Anonymous.getUuid());
+ deleteLink(deleteLink, true, golbalArtifact);
+
+ Artifact userArt = ArtifactQuery.getArtifactFromId(new Integer(accountId), CoreBranches.COMMON);
+ Conditions.checkNotNull(userArt, "User Artifact accountId: " + accountId);
+ deleteLink(deleteLink, false, userArt);
+ }
+
+ public static void deleteLink(Link deleteLink, boolean global) throws Exception {
+ deleteLink(deleteLink, global, getStoreArtifact(global));
+ }
+
+ public static void deleteLink(Link deleteLink, boolean global, Artifact useArtifact) throws Exception {
+ String webPrefStr = useArtifact.getSoleAttributeValue(CoreAttributeTypes.WebPreferences, "{}");
+ AccountWebPreferences webPrefs = new AccountWebPreferences(webPrefStr, useArtifact.getName());
+ Link remove = webPrefs.getLinks().remove(deleteLink.getId());
+ if (remove != null) {
+ saveWebPrefsToArtifactAndKickEvent(global, useArtifact, webPrefs);
+ }
+ }
+
+ public static void addUpdateLink(Link link, boolean global) throws Exception {
+ addUpdateLink(getStoreArtifact(global).getArtId(), link, global);
+ }
+
+ /**
+ * Update existing link in shared/global web preferences and store
+ */
+ public static void addUpdateLink(int accountId, Link link, boolean global) throws Exception {
+ Artifact useArtifact = getStoreArtifact(global);
+ Conditions.checkNotNull(useArtifact, "Could not find store artifact for accountId: " + accountId);
+
+ String webPrefStr = useArtifact.getSoleAttributeValue(CoreAttributeTypes.WebPreferences, null);
+ if (webPrefStr != null) {
+ AccountWebPreferences webPrefs = new AccountWebPreferences(webPrefStr, useArtifact.getName());
+ boolean found = false;
+ for (Entry<String, Link> stored : webPrefs.getLinks().entrySet()) {
+ if (stored.getKey().equals(link.getId())) {
+ setLinkFromLink(link, stored.getValue());
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ webPrefs.getLinks().put(link.getId(), link);
+ }
+ saveWebPrefsToArtifactAndKickEvent(global, useArtifact, webPrefs);
+ }
+ }
+
+ public static Artifact getStoreArtifact(boolean global) {
+ if (global) {
+ return ArtifactQuery.getArtifactFromId(SystemUser.Anonymous.getUuid(), CoreBranches.COMMON);
+ }
+ return LinkUtil.getPersonalLinksArtifact();
+ }
+
+ public static void saveWebPreferences(AccountWebPreferences webPrefs, boolean global) throws Exception {
+ saveWebPreferences(webPrefs, global, getStoreArtifact(global));
+ }
+
+ public static void saveWebPreferences(AccountWebPreferences webPrefs, boolean global, Artifact useArtifact) throws Exception {
+ saveWebPrefsToArtifactAndKickEvent(global, useArtifact, webPrefs);
+ }
+
+ public static boolean setLinkFromLink(Link fromLink, Link toLink) {
+ boolean changed = false;
+ if (!toLink.getName().equals(fromLink.getName())) {
+ toLink.setName(fromLink.getName());
+ changed = true;
+ }
+ if (!Collections.isEqual(fromLink.getTags(), toLink.getTags())) {
+ toLink.setTags(fromLink.getTags());
+ changed = true;
+ }
+ if (!toLink.getTeam().equals(fromLink.getTeam())) {
+ toLink.setTeam(fromLink.getTeam());
+ changed = true;
+ }
+ if (!toLink.getUrl().equals(fromLink.getUrl())) {
+ toLink.setUrl(fromLink.getUrl());
+ changed = true;
+ }
+ return changed;
+ }
+
+ private static void saveWebPrefsToArtifactAndKickEvent(boolean global, Artifact useArtifact, AccountWebPreferences webPrefs) throws Exception {
+ ObjectMapper mapper = new ObjectMapper();
+ String json = mapper.writeValueAsString(webPrefs);
+ useArtifact.setSoleAttributeValue(CoreAttributeTypes.WebPreferences, json);
+ useArtifact.persist("Add web preferences links to " + useArtifact.toStringWithId());
+
+ TopicEvent event =
+ new TopicEvent((global ? FrameworkEvents.GLOBAL_WEB_PREFERENCES : FrameworkEvents.PERSONAL_WEB_PREFERENCES),
+ "links", webPrefs.getLinks().toString(), (global ? EventType.LocalAndRemote : EventType.LocalOnly));
+ OseeEventManager.kickTopicEvent(LinkUtil.class, event);
+ }
+
+ public static Link getExistingLink(Link link, AccountWebPreferences webPrefs) {
+ return getExistingLink(link, webPrefs.getLinks());
+ }
+
+ public static Link getExistingLink(Link link, Map<String, Link> links) {
+ for (Link existingLink : links.values()) {
+ if (existingLink.getId().equals(link.getId())) {
+ return existingLink;
+ }
+ }
+ return null;
+ }
+
+ public static void upateLinkFromDialog(EditLinkDialog dialog, Link link) throws Exception {
+ link.setName(dialog.getEntry());
+ link.setUrl(dialog.getUrl());
+ boolean global = dialog.isChecked();
+ for (String tag : dialog.getTags().split(",")) {
+ tag = tag.replaceAll(" ", "");
+ link.getTags().add(tag);
+ }
+ int accountId = 0;
+ if (link.getId() == null) {
+ link.setId(GUID.create());
+ }
+ if (global) {
+ accountId = SystemUser.Anonymous.getUuid().intValue();
+ link.setTeam("Guest");
+ } else {
+ User user = UserManager.getUser();
+ accountId = user.getUuid().intValue();
+ link.setTeam(user.getName());
+ }
+ LinkUtil.addUpdateLink(accountId, link, global);
+ }
+
+ public static Artifact getPersonalLinksArtifact() {
+ return ArtifactQuery.getArtifactFromId(UserManager.getUser().getArtId(), CoreBranches.COMMON);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinksNavigateViewItems.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinksNavigateViewItems.java
new file mode 100644
index 00000000000..8601c45c64e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/links/LinksNavigateViewItems.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.links;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osee.account.rest.model.AccountWebPreferences;
+import org.eclipse.osee.account.rest.model.Link;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.logging.OseeLevel;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.IXNavigateCommonItem;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.IXNavigateMenuItem;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateCommonItems;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateUrlItem;
+import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateViewItems;
+import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
+import org.eclipse.osee.framework.ui.skynet.internal.Activator;
+import org.eclipse.osee.framework.ui.skynet.util.DbConnectionUtility;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.program.Program;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class LinksNavigateViewItems implements XNavigateViewItems, IXNavigateCommonItem {
+
+ private final static LinksNavigateViewItems instance = new LinksNavigateViewItems();
+ public static final long TOP_LINK_ID = 4561556789L;
+ private final List<XNavigateItem> items = new CopyOnWriteArrayList<>();
+ private boolean ensurePopulatedRanOnce = false;
+
+ public static LinksNavigateViewItems getInstance() {
+ return instance;
+ }
+
+ @Override
+ public List<XNavigateItem> getSearchNavigateItems() {
+ ensurePopulated();
+ return items;
+ }
+
+ private synchronized void ensurePopulated() {
+ if (!ensurePopulatedRanOnce) {
+ if (DbConnectionUtility.areOSEEServicesAvailable().isFalse()) {
+ return;
+ }
+ this.ensurePopulatedRanOnce = true;
+
+ try {
+ addOseeLinksSectionChildren(null, items);
+
+ XNavigateCommonItems.addCommonNavigateItems(items, Arrays.asList(getSectionId()));
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ }
+
+ public static void addOseeLinksSectionChildren(XNavigateItem parentItem, List<XNavigateItem> resultItems) throws OseeCoreException {
+ new AddNewLinkNavigateItem(parentItem);
+ new EditLinksNavigateItem(parentItem, false);
+ new EditLinksNavigateItem(parentItem, true);
+ try {
+ AccountWebPreferences data = LinkUtil.getAccountsPreferencesData(false);
+ for (Link link : data.getLinks().values()) {
+ XNavigateUrlItem urlItem = new XNavigateUrlItem(parentItem, link.getName() + getTagsStr(link, false),
+ link.getUrl(), true, FrameworkImage.LINK);
+ urlItem.addMenuItem(editListener);
+ urlItem.setData(link);
+ resultItems.add(urlItem);
+ }
+
+ data = LinkUtil.getAccountsPreferencesData(true);
+ for (Link link : data.getLinks().values()) {
+ XNavigateUrlItem urlItem = new XNavigateUrlItem(parentItem, link.getName() + getTagsStr(link, true),
+ link.getUrl(), true, FrameworkImage.LINK);
+ urlItem.setData(link);
+ urlItem.addMenuItem(editListener);
+ resultItems.add(urlItem);
+ }
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+
+ private static final IXNavigateMenuItem editListener = new IXNavigateMenuItem() {
+
+ @Override
+ public void addMenuItems(final Menu menu, final TreeItem selectedTreeItem) {
+ if (((XNavigateUrlItem) selectedTreeItem.getData()).getData() instanceof Link) {
+ openExternallyMenuItem(menu, selectedTreeItem);
+ openInternallyMenuItem(menu, selectedTreeItem);
+ new MenuItem(menu, SWT.SEPARATOR);
+ addEditMenuItem(menu, selectedTreeItem);
+ addDeleteMenuItem(menu, selectedTreeItem);
+ }
+ }
+
+ private void openExternallyMenuItem(final Menu menu, final TreeItem selectedTreeItem) {
+ final XNavigateItem navItem = (XNavigateItem) selectedTreeItem.getData();
+ final Link link = (Link) navItem.getData();
+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
+ menuItem.setText(String.format("Open Externally"));
+ menuItem.setToolTipText(link.getUrl());
+ menuItem.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ Program.launch(((Link) navItem.getData()).getUrl());
+ }
+ });
+ }
+
+ private void openInternallyMenuItem(final Menu menu, final TreeItem selectedTreeItem) {
+ final XNavigateItem navItem = (XNavigateItem) selectedTreeItem.getData();
+ final Link link = (Link) navItem.getData();
+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
+ menuItem.setText(String.format("Open Internally"));
+ menuItem.setToolTipText(link.getUrl());
+ menuItem.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
+ try {
+ IWebBrowser browser =
+ browserSupport.createBrowser(SWT.None, "osee.links." + link.getId(), link.getName(), "");
+ browser.openURL(new URL(link.getUrl()));
+ } catch (Exception ex) {
+ OseeLog.log(LinksNavigateViewItems.class, OseeLevel.SEVERE_POPUP, ex);
+ }
+ }
+ });
+ }
+
+ private void addEditMenuItem(final Menu menu, final TreeItem selectedTreeItem) {
+ final XNavigateItem navItem = (XNavigateItem) selectedTreeItem.getData();
+ Link link = (Link) navItem.getData();
+ if (link != null) {
+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
+ menuItem.setText(String.format("Edit [%s]", link.getName()));
+ menuItem.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ handleEditMenuItemSelected(navItem, selectedTreeItem);
+ }
+ });
+ }
+ }
+
+ private void addDeleteMenuItem(final Menu menu, final TreeItem selectedTreeItem) {
+ final XNavigateItem navItem = (XNavigateItem) selectedTreeItem.getData();
+ Link link = (Link) navItem.getData();
+ if (link != null) {
+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
+ menuItem.setText(String.format("Delete [%s]", link.getName()));
+ menuItem.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ try {
+ LinkUtil.deleteLink(String.valueOf(UserManager.getUser().getArtId()), link);
+ } catch (Exception ex) {
+ OseeLog.log(LinksNavigateViewItems.class, OseeLevel.SEVERE_POPUP, ex);
+ }
+ }
+ });
+ }
+ }
+
+ public void handleEditMenuItemSelected(XNavigateItem urlItem, TreeItem selectedTreeItem) {
+ Link link = (Link) urlItem.getData();
+ if (link != null) {
+ EditLinkDialog dialog = new EditLinkDialog(link);
+ if (dialog.open() == Window.OK) {
+ try {
+ LinkUtil.upateLinkFromDialog(dialog, link);
+ } catch (Exception ex) {
+ OseeLog.log(LinksNavigateViewItems.class, OseeLevel.SEVERE_POPUP, ex);
+ }
+ }
+ }
+ }
+
+ };
+
+ private static String getTagsStr(Link link, boolean global) {
+ if (!link.getTags().isEmpty()) {
+ return " (" + Collections.toString(", ", link.getTags()) + (global ? ", global" : "") + ")";
+ }
+ return "";
+ }
+
+ @Override
+ public void createCommonSection(List<XNavigateItem> items, List<String> excludeSectionIds) {
+ try {
+ XNavigateItem linkItem = new XNavigateItem(null, "Links", FrameworkImage.LINK);
+ linkItem.setId(TOP_LINK_ID);
+ addOseeLinksSectionChildren(linkItem, new LinkedList<>());
+ items.add(linkItem);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Can't create OSEE Links section", ex);
+ }
+ }
+
+ @Override
+ public String getSectionId() {
+ return "Links";
+ }
+
+ public static void reloadLinks(XNavigateItem linkItem) {
+ linkItem.getChildren().clear();
+ addOseeLinksSectionChildren(linkItem, new LinkedList<>());
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/util/FrameworkEvents.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/util/FrameworkEvents.java
new file mode 100644
index 00000000000..9f8e716abdc
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/util/FrameworkEvents.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.ui.skynet.util;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class FrameworkEvents {
+
+ public static final String PERSONAL_WEB_PREFERENCES = "framework/web/prefs/modified/links/personal";
+ public static final String GLOBAL_WEB_PREFERENCES = "framework/web/prefs/modified/links/global";
+ public static final String FRAMEWORK_LINK_EDIT = "framework/link/edit";
+
+ private FrameworkEvents() {
+ // utility class
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/dialog/EntryCheckDialog.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/dialog/EntryCheckDialog.java
index d22a4772431..6fbc1a2e97f 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/dialog/EntryCheckDialog.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/dialog/EntryCheckDialog.java
@@ -45,7 +45,7 @@ public class EntryCheckDialog extends EntryDialog {
text.setFocus();
text.setDisplayLabel(false);
text.set(checked);
- text.createWidgets(parent, 2);
+ text.createWidgets(parent, 1);
SelectionListener selectionListener = new SelectionAdapter() {

Back to the top