Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Support for Tasks Quick Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Feb 18, 2014
1 parent 27087e0 commit 50defd3
Show file tree
Hide file tree
Showing 11 changed files with 1,687 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* Copyright (c) 2012, 2014 Pivotal Software, Inc.
* 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
Expand Down Expand Up @@ -280,7 +280,12 @@ public static String getTasks(ILaunchConfiguration conf) {
}

public static void setTasks(ILaunchConfigurationWorkingCopy conf, List<String> checked) {
conf.setAttribute(TASK_LIST, checked);
StringBuilder sb = new StringBuilder();
for (String task : checked) {
sb.append(task);
sb.append('\n');
}
conf.setAttribute(TASK_TEXT, sb.toString());
}

@SuppressWarnings("unchecked")
Expand All @@ -299,13 +304,17 @@ public static List<String> getTasksList(ILaunchConfiguration conf) {
return DEFAULT_TASK_LIST;
}
} else {
List<String> tasks = new ArrayList<String>();
Matcher matcher = Pattern.compile("\\S+").matcher(tasksText); //$NON-NLS-1$
while(matcher.find()) {
tasks.add(matcher.group());
}
return tasks;
return parseTasks(tasksText);
}
}

private static List<String> parseTasks(String tasksText) {
List<String> tasks = new ArrayList<String>();
Matcher matcher = Pattern.compile("\\S+").matcher(tasksText); //$NON-NLS-1$
while(matcher.find()) {
tasks.add(matcher.group());
}
return tasks;
}

public static void setTasks(ILaunchConfigurationWorkingCopy conf, String tasksText) {
Expand Down Expand Up @@ -374,7 +383,7 @@ public static ILaunchConfiguration createDefault(GradleProject project, String t
ILaunchConfigurationWorkingCopy conf = null;
try {
conf = createDefault(project, LaunchUtil.generateConfigName(project.getName()+" "+task));
setTasks(conf, Arrays.asList(task));
setTasks(conf, parseTasks(task));
if (save) {
return conf.doSave();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2014 Pivotal Software, Inc.
* 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:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.gradle.core.util;

import java.util.Collection;
import java.util.LinkedList;

/**
* Linked list based implementation of a capacity restricted stack/queue
*
* @author Alex Boyko
*
* @param <E>
*/
public class RestrictedCapacityStack<E> extends LinkedList<E> {

private static final long serialVersionUID = 7642692882661680882L;

private static final int DEFAULT_CAPACITY = 30;

private int maxCapacity = DEFAULT_CAPACITY;

public RestrictedCapacityStack() {
super();
}

public RestrictedCapacityStack(int maxCapacity) {
this();
this.maxCapacity = maxCapacity;
}

@Override
public boolean addAll(int index, Collection<? extends E> c) {
boolean added = super.addAll(index, c);
adjustSize();
return added;
}

@Override
public void add(int index, E element) {
super.add(index, element);
adjustSize();
}

@Override
public boolean add(E e) {
boolean added = super.add(e);
if (added) {
adjustSize();
}
return added;
}

final protected void adjustSize() {
while (size() > maxCapacity) {
removeLast();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* Copyright (c) 2012, 2014 Pivotal Software, Inc.
* 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
Expand All @@ -12,6 +12,8 @@

import static org.springsource.ide.eclipse.gradle.core.util.JobUtil.NO_RULE;

import java.util.Collections;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
Expand All @@ -26,6 +28,7 @@
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
Expand All @@ -42,14 +45,14 @@
import org.eclipse.ui.part.ViewPart;
import org.gradle.tooling.model.Task;
import org.springsource.ide.eclipse.gradle.core.GradleProject;
import org.springsource.ide.eclipse.gradle.core.classpathcontainer.FastOperationFailedException;
import org.springsource.ide.eclipse.gradle.core.launch.GradleLaunchConfigurationDelegate;
import org.springsource.ide.eclipse.gradle.core.util.GradleRunnable;
import org.springsource.ide.eclipse.gradle.core.util.JobUtil;
import org.springsource.ide.eclipse.gradle.ui.util.DialogSettingsUtil;
import org.springsource.ide.eclipse.gradle.ui.util.SelectionUtils;

/**
* @author Kris De Volder
* @author Alex Boyko
* @since 3.5
*/
Expand Down Expand Up @@ -86,6 +89,7 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
private Action refreshAction;
private Action toggleProjectTasks;
private Action doubleClickAction;
private TasksConsoleAction tasksConsoleAction;

private SelectionListener selectionListener;

Expand All @@ -106,6 +110,7 @@ public void projectSelected(GradleProject p) {
if (viewer!=null) {
projectSelector.setProject(p);
viewer.setInput(p);
tasksConsoleAction.selectChanged(new StructuredSelection(Collections.singletonList(p.getProject())));
saveDialogSettings();
}
}
Expand Down Expand Up @@ -181,15 +186,17 @@ private void fillContextMenu(IMenuManager manager) {
}

private void fillLocalToolBar(IToolBarManager manager) {
manager.add(toggleProjectTasks);
manager.add(tasksConsoleAction);
manager.add(linkWithSelectionAction);
manager.add(refreshAction);
manager.add(toggleProjectTasks);
}

private void makeActions() {
tasksConsoleAction = new TasksConsoleAction();
toggleProjectTasks = new ToggleProjectTasks(this, displayProjectLocalTasks);
linkWithSelectionAction = new ToggleLinkingAction(this);
refreshAction = new RefreshAction(this);
toggleProjectTasks = new ToggleProjectTasks(this, displayProjectLocalTasks);
doubleClickAction = new Action() {
public void run() {
ISelection selection = viewer.getSelection();
Expand All @@ -199,14 +206,6 @@ public void run() {
GradleProject project = projectSelector.getProject();
if (project!=null) {
String taskStr = displayProjectLocalTasks ? task.getPath() : task.getName();
// if (displayProjectLocalTasks) {
// try {
// String projectPath = project.getGradleModel().getGradleProject().getPath();
// taskStr = taskStr.substring(projectPath.length());
// } catch (Exception e) {
// // ignore
// }
// }
final ILaunchConfiguration conf = GradleLaunchConfigurationDelegate.getOrCreate(project, taskStr);
JobUtil.schedule(NO_RULE, new GradleRunnable(project.getDisplayName() + " " + taskStr) {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2014 Pivotal Software, Inc.
* 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:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.gradle.ui.taskview;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.springsource.ide.eclipse.gradle.ui.GradleUI;
import org.springsource.ide.eclipse.gradle.ui.actions.ConsoleInplaceDialogActionDelegate;

/**
* A proxy action to {@link ConsoleInplaceDialogActionDelegate}
*
* @author Alex Boyko
*
*/
public class TasksConsoleAction extends Action {

private ConsoleInplaceDialogActionDelegate delegateAction;

public TasksConsoleAction() {
super(null);
this.delegateAction = new ConsoleInplaceDialogActionDelegate();
setDescription("Tasks Quick Launcher");
setToolTipText("Displays Tasks Quick Launcher to launch multiple tasks");
setImageDescriptor(GradleUI.getDefault().getImageRegistry().getDescriptor(GradleUI.IMAGE_LAUNCH));
}

/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
delegateAction.run(this);
}

public void selectChanged(ISelection selection) {
delegateAction.selectionChanged(this, selection);
}

}
16 changes: 16 additions & 0 deletions org.springsource.ide.eclipse.gradle.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
label="Toggle DSL Support"
menubarPath="org.springsource.ide.eclipse.gradle.menu/group1">
</action>
<action
class="org.springsource.ide.eclipse.gradle.ui.actions.ConsoleInplaceDialogActionDelegate"
enablesFor="+"
icon="icons/gradle-launch.png"
id="org.springsource.ide.eclipse.gradle.ui.actions.Console"
label="Tasks Quick Launcher"
menubarPath="org.springsource.ide.eclipse.gradle.menu/group1">
</action>
</objectContribution>
<objectContribution
adaptable="true"
Expand Down Expand Up @@ -134,6 +142,14 @@
label="Toggle DSL Support"
menubarPath="org.springsource.ide.eclipse.gradle.workingSetMenu/refresh">
</action>
<action
class="org.springsource.ide.eclipse.gradle.ui.actions.ConsoleInplaceDialogActionDelegate"
enablesFor="+"
icon="icons/gradle-launch.png"
id="org.springsource.ide.eclipse.gradle.ui.actions.Console"
label="Tasks Quick Launcher"
menubarPath="org.springsource.ide.eclipse.gradle.workingSetMenu/refresh">
</action>
</objectContribution>
</extension>
<extension
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* Copyright (c) 2012, 2014 Pivotal Software, Inc.
* 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
Expand Down Expand Up @@ -40,14 +40,16 @@ public class GradleUI extends AbstractUIPlugin {
public static final String IMAGE_PROJECT_FOLDER = "projectFolder"; //$NON-NLS-1$
public static final String IMAGE_MULTIPROJECT_FOLDER = "multiProjectFolder"; //$NON-NLS-1$
public static final String IMAGE_MULTIPROJECT_FOLDER_DISABLED = "multiProjectFolderDisabled"; //$NON-NLS-1$
public static final String IMAGE_LAUNCH = "launch"; //$NON-NLS-1$

private static final Map<String, String> IMAGE_DESCRIPTOR_MAP = new HashMap<String, String>();

static {
IMAGE_DESCRIPTOR_MAP.put(IMAGE_TARGET, "icons/target.gif");
IMAGE_DESCRIPTOR_MAP.put(IMAGE_PROJECT_FOLDER, "icons/gradle-proj-folder.png");
IMAGE_DESCRIPTOR_MAP.put(IMAGE_MULTIPROJECT_FOLDER, "icons/gradle-multiproj-folder.png");
IMAGE_DESCRIPTOR_MAP.put(IMAGE_MULTIPROJECT_FOLDER_DISABLED, "icons/gradle-multiproj-folder-disabled.png");
IMAGE_DESCRIPTOR_MAP.put(IMAGE_MULTIPROJECT_FOLDER_DISABLED, "icons/gradle-multiproj-folder-disabled.png");
IMAGE_DESCRIPTOR_MAP.put(IMAGE_LAUNCH, "icons/gradle-launch.png");
}

// The shared instance
Expand Down
Loading

1 comment on commit 50defd3

@paulvi
Copy link
Contributor

@paulvi paulvi commented on 50defd3 Apr 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BoykoAlex
That is great feature. Thanks so much.

Please take look at #33 #34 #36

Please sign in to comment.