Skip to content

Commit

Permalink
create hyperlink for text transfer type
Browse files Browse the repository at this point in the history
for #360
  • Loading branch information
eric-milles committed Oct 31, 2023
1 parent 4472787 commit ba19ed3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public class ShelvesetsTable extends TableControl {
private static final String SHELVESET_NAME_COLUMN_ID = "name"; //$NON-NLS-1$
private DateFormat dateFormat = DateHelper.getDefaultDateTimeFormat();

private TSWAHyperlinkBuilder tswaHyperlinkBuilder;
private IAction copyAction;
private IAction selectAllAction;

private TSWAHyperlinkBuilder tswaHyperlinkBuilder;
private ActionKeyBindingSupport actionCommandSupport;

/**
Expand Down Expand Up @@ -261,19 +260,14 @@ public void setShelvesets(final Shelveset[] shelvesets, final TFSRepository repo
protected Object getTransferData(final Transfer transferType, final Object[] selectedElements) {
final Shelveset[] selectedShelvesets = (Shelveset[]) selectedElements;

if (transferType.getClass().getName().equals("org.eclipse.swt.dnd.HTMLTransfer") //$NON-NLS-1$
&& tswaHyperlinkBuilder != null) {
final StringBuilder sb = new StringBuilder();
if (tswaHyperlinkBuilder != null && transferType.getClass().getName().equals("org.eclipse.swt.dnd.HTMLTransfer")) { //$NON-NLS-1$
// Create HTML to copy
final StringBuffer sb = new StringBuffer();
for (int j = 0; j < selectedShelvesets.length; j++) {
// TODO: Consider adding more data in the title so that
// there is a tooltip?
final Shelveset shelveset = selectedShelvesets[j];
for (int i = 0; i < selectedShelvesets.length; i += 1) {
final Shelveset shelveset = selectedShelvesets[i];
// TODO: Consider adding more data in the title so that there is a tooltip?
sb.append("<a href=\""); //$NON-NLS-1$
sb.append(
tswaHyperlinkBuilder.getShelvesetDetailsURL(
shelveset.getName(),
shelveset.getOwnerName()).toString());
sb.append(tswaHyperlinkBuilder.getShelvesetDetailsURL(shelveset.getName(), shelveset.getOwnerName()));
sb.append("\">"); //$NON-NLS-1$
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
Expand All @@ -283,20 +277,23 @@ protected Object getTransferData(final Transfer transferType, final Object[] sel
}
// remove the last <br/>
sb.setLength(sb.length() - NewlineUtils.PLATFORM_NEWLINE.length() - 5);
return sb.toString();
} else {
// Assume text transfer type
for (int i = 0; i < selectedShelvesets.length; i += 1) {
final Shelveset shelveset = selectedShelvesets[i];
if (tswaHyperlinkBuilder != null) {
sb.append(tswaHyperlinkBuilder.getShelvesetDetailsURL(shelveset.getName(), shelveset.getOwnerName()));
} else {
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
sb.append(shelveset.getOwnerName());
}
sb.append(NewlineUtils.PLATFORM_NEWLINE);
}
// remove the last newline
sb.setLength(sb.length() - NewlineUtils.PLATFORM_NEWLINE.length());
}

// Assume text transfer type
final StringBuffer sb = new StringBuffer();
for (int j = 0; j < selectedShelvesets.length; j++) {
final Shelveset shelveset = selectedShelvesets[j];
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
sb.append(shelveset.getOwnerName());
sb.append(NewlineUtils.PLATFORM_NEWLINE);
}
// remove the last newline
sb.setLength(sb.length() - NewlineUtils.PLATFORM_NEWLINE.length());
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public class ShelvesetDetailsDialog extends AbstractCheckinControlDialog {

private boolean preserveShelveset = true;
private boolean restoreData = true;
private TSWAHyperlinkBuilder tswaHyperlinkBuilder;

/**
* The lazily created clipboard and transferTypes. The two field starts off
* as <code>null</code>, and allocated if needed.
* The lazily created clipboard and transferTypes.
*/
private Clipboard clipboard = null;
private Transfer[] transferTypes = null;
private Clipboard clipboard;
private Transfer[] transferTypes;

private TSWAHyperlinkBuilder tswaHyperlinkBuilder;

public ShelvesetDetailsDialog(
final Shell parentShell,
Expand Down Expand Up @@ -412,7 +412,7 @@ public ChangeItem[] getCheckedChangeItems() {
}

/**
* Generate hyperlink for this shelveset
* Generates hyperlink for the shelveset.
*
* @param transferType
* @return
Expand All @@ -421,27 +421,40 @@ private Object getTransferData(final Transfer transferType) {
if (tswaHyperlinkBuilder == null) {
tswaHyperlinkBuilder = new TSWAHyperlinkBuilder(repository.getVersionControlClient().getConnection());
}
final StringBuffer sb = new StringBuffer();
if (transferType.getClass().getName().equals("org.eclipse.swt.dnd.HTMLTransfer") //$NON-NLS-1$
&& tswaHyperlinkBuilder != null) {

String shelvesetHyperlink = null;
if (tswaHyperlinkBuilder != null) {
shelvesetHyperlink = tswaHyperlinkBuilder.getShelvesetDetailsURL(shelveset.getName(), shelveset.getOwnerName()).toString();
}

final StringBuilder sb = new StringBuilder();
if (shelvesetHyperlink != null && transferType.getClass().getName().equals("org.eclipse.swt.dnd.HTMLTransfer")) { //$NON-NLS-1$
// Create HTML to copy
sb.append("<a href=\""); //$NON-NLS-1$
sb.append(
tswaHyperlinkBuilder.getShelvesetDetailsURL(shelveset.getName(), shelveset.getOwnerName()).toString());
sb.append(shelvesetHyperlink);
sb.append("\">"); //$NON-NLS-1$
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
sb.append(shelveset.getOwnerName());
sb.append("</a>"); //$NON-NLS-1$
} else {
// Assume text transfer type
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
sb.append(shelveset.getOwnerName());
if (shelvesetHyperlink != null) {
sb.append(shelvesetHyperlink);
} else {
sb.append(shelveset.getName());
sb.append(";"); //$NON-NLS-1$
sb.append(shelveset.getOwnerName());
}
}

return sb.toString();
}

/**
* @param composite
* @return
*/
public final Clipboard getClipboard(final Composite composite) {
if (clipboard == null) {
clipboard = new Clipboard(composite.getDisplay());
Expand All @@ -451,7 +464,7 @@ public final Clipboard getClipboard(final Composite composite) {
}

/**
* Get transferTypes, if null, create them
* Gets transferTypes, if null, creates them.
*
* @return
*/
Expand Down

0 comments on commit ba19ed3

Please sign in to comment.