package com.urswolfer.intellij.plugin.gerrit.ui.action;

import com.google.common.base.Optional;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.inject.Inject;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.urswolfer.intellij.plugin.gerrit.GerritModule;
import com.urswolfer.intellij.plugin.gerrit.git.GerritGitUtil;
import icons.Git4ideaIcons;

/**
 * @author Urs Wolfer
 */
@SuppressWarnings("ComponentNotRegistered") // proxy class below is registered
public class StarAction extends AbstractLoggedInChangeAction {
    @Inject
    private GerritGitUtil gerritGitUtil;

    public StarAction() {
        super("Star", "Switch star status of change", Git4ideaIcons.Star);
    }

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Optional<ChangeInfo> selectedChange = getSelectedChange(anActionEvent);
        if (!selectedChange.isPresent()) {
            return;
        }
        Project project = anActionEvent.getData(PlatformDataKeys.PROJECT);
        ChangeInfo changeInfo = selectedChange.get();
        gerritUtil.changeStarredStatus(changeInfo.id, !(changeInfo.starred != null && changeInfo.starred), project);
    }

    public static class Proxy extends StarAction {
        private final StarAction delegate;

        public Proxy() {
            delegate = GerritModule.getInstance(StarAction.class);
        }

        @Override
        public void update(AnActionEvent e) {
            delegate.update(e);
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            delegate.actionPerformed(e);
        }
    }
}

@@ -149,41 +149,8 @@
 fo;%0A
-import com.google.inject.Inject;%0A
 impo
@@ -201,16 +201,16 @@
 nEvent;%0A
+
 import c
@@ -367,71 +367,8 @@
 le;%0A
-import com.urswolfer.intellij.plugin.gerrit.git.GerritGitUtil;%0A
 impo
@@ -501,16 +501,16 @@
 istered%0A
+
 public c
@@ -567,61 +567,8 @@
 on %7B
-%0A    @Inject%0A    private GerritGitUtil gerritGitUtil;
 %0A%0A  

remove unused injection