Skip to main content
summaryrefslogtreecommitdiffstats
blob: 966f293a8f06273556e583da9c39754b7d84497c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2009 Atlassian and others.
 * 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:
 *     Atlassian - initial API and implementation
 ******************************************************************************/

package com.atlassian.connector.eclipse.internal.crucible.ui.actions;

import com.atlassian.connector.eclipse.internal.crucible.core.CrucibleUtil;
import com.atlassian.connector.eclipse.internal.crucible.ui.CrucibleImages;
import com.atlassian.connector.eclipse.internal.crucible.ui.CrucibleUiPlugin;
import com.atlassian.connector.eclipse.internal.crucible.ui.CrucibleUiUtil;
import com.atlassian.connector.eclipse.internal.crucible.ui.IReviewAction;
import com.atlassian.connector.eclipse.internal.crucible.ui.IReviewActionListener;
import com.atlassian.theplugin.commons.crucible.api.model.Comment;
import com.atlassian.theplugin.commons.crucible.api.model.Review;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.actions.BaseSelectionListenerAction;

public class PostDraftCommentAction extends BaseSelectionListenerAction implements IReviewAction {

	private static final String PUBLISH_COMMENT = "Publish Comment";

	private Review review;

	private IReviewActionListener actionListener;

	public PostDraftCommentAction() {
		super(PUBLISH_COMMENT);
		setEnabled(false);
	}

	public void run() {
		final Comment comment = (Comment) getStructuredSelection().getFirstElement();
//		IAction action = new BackgroundJobReviewAction("Publish Comment", review,
//				WorkbenchUtil.getShell(), "Publishing selected comment for review " + review.getPermId().getId(),
//				CrucibleImages.COMMENT_POST, new RemoteCrucibleOperation() {
//			public void run(CrucibleServerFacade2 server, ConnectionCfg serverCfg)
//					throws CrucibleLoginException, RemoteApiException, ServerPasswordNotProvidedException {
//				server.publishComment(serverCfg, review.getPermId(), comment.getPermId());
//			}
//		}, true);
//		action.run();

		if (actionListener != null) {
			actionListener.actionRan(this);
		}
	}

	@Override
	protected boolean updateSelection(IStructuredSelection selection) {
		review = null;

		Object element = selection.getFirstElement();
		if (element instanceof Comment && selection.size() == 1) {
			review = getActiveReview();
			if (review != null && CrucibleUiUtil.canModifyComment(review, (Comment) element)
					&& CrucibleUtil.canPublishDraft((Comment) element)) {
				return true;
			}
		}
		return false;
	}

	protected Review getActiveReview() {
		return CrucibleUiPlugin.getDefault().getActiveReviewManager().getActiveReview();
	}

	public void setActionListener(IReviewActionListener listener) {
		this.actionListener = listener;
	}

	@Override
	public ImageDescriptor getImageDescriptor() {
		return CrucibleImages.COMMENT_POST;
	}

	@Override
	public String getToolTipText() {
		return PUBLISH_COMMENT;
	}
}

Back to the top