mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
LaunhBar - some API changes and cleanup
* Project provider to react on project changes (i.e. when nature changed) * Added concept of open descriptor - which will be visible in UI, this will allow not to remap to null, reuse objects for other reasons, and eventually I want to replace object map into 1:1 mapping without nulls * Removed throwing CoreException from getLaunchDescriptors (it does not need to throw it) * Project based type now checks if project is open * Fixed copyright * Added interface for ILaunchDescriptorProjectBased Change-Id: I3277f5910c7df1bb4aa3e809dda3b61921dcad6e Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/31321
This commit is contained in:
parent
4d4ab6cafd
commit
1bf2aa825f
12 changed files with 242 additions and 153 deletions
|
@ -289,19 +289,19 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchDescriptorsNull() {
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
public void testGetOpenLaunchDescriptorsNull() {
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(0, launchDescriptors.length);
|
||||
}
|
||||
|
||||
public void testGetLaunchDescriptors() {
|
||||
public void testGetOpenLaunchDescriptors() {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
}
|
||||
|
||||
public void testGetLaunchDescriptorsSort() {
|
||||
public void testGetOpenLaunchDescriptorsSort() {
|
||||
final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
|
||||
manager.addTargetType(targetType);
|
||||
ConfigBasedLaunchDescriptorType descType1 = new ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
|
||||
|
@ -320,7 +320,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager.addConfigProvider(descType3.getId(), targetType.getId(), true, provider);
|
||||
targetType.targets.add(mytarget);
|
||||
manager.launchObjectAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
assertSame(res[0], launchDescriptors[0]);
|
||||
|
@ -330,7 +330,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
public void testLaunchObjectAdded() throws CoreException {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
assertEquals(lc.getName(), launchDescriptors[0].getName());
|
||||
|
@ -342,7 +342,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager.launchObjectAdded(lc);
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype);
|
||||
manager.launchObjectAdded(lc2);
|
||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
assertEquals(2, manager.getOpenLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -350,7 +350,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
basicSetup();
|
||||
assertNull(manager.launchObjectChanged(lc));
|
||||
manager.launchObjectAdded(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
assertNotNull(manager.launchObjectChanged(lc));
|
||||
}
|
||||
|
||||
|
@ -362,6 +362,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
IPath path = new Path(projectName);
|
||||
when(project.getFullPath()).thenReturn(path);
|
||||
when(project.getType()).thenReturn(IResource.PROJECT);
|
||||
when(project.isOpen()).thenReturn(true);
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -407,23 +408,23 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
projectMappingSetup();
|
||||
// user created a project
|
||||
manager.launchObjectAdded(aaa);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertTrue(manager.getLaunchDescriptors()[0].getName().startsWith(aaa.getName()));
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
assertTrue(manager.getOpenLaunchDescriptors()[0].getName().startsWith(aaa.getName()));
|
||||
// user clicked on descriptor geer to edit lc, new lc is created
|
||||
manager.launchConfigurationAdded(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getLaunchDescriptors()[0].getName());
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getOpenLaunchDescriptors()[0].getName());
|
||||
// user cloned lc and changed some settings
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype);
|
||||
mockLCProject(lc2, aaa.getName());
|
||||
manager.launchConfigurationAdded(lc2);
|
||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
assertEquals(2, manager.getOpenLaunchDescriptors().length);
|
||||
// user deleted lc
|
||||
userDeletesLC(lc2);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
// user deleted last lc, now we back to project default
|
||||
userDeletesLC(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
protected void userDeletesLC(ILaunchConfiguration lc2) {
|
||||
|
@ -443,6 +444,11 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
protected boolean ownsProject(IProject element) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType() {
|
||||
return lctype;
|
||||
}
|
||||
};
|
||||
provider = new ProjectBasedLaunchConfigurationProvider(lctype.getIdentifier()) {
|
||||
protected IProject getProject(ILaunchConfiguration llc) {
|
||||
|
@ -453,18 +459,21 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
basicSetup();
|
||||
aaa = mockProject("aaa");
|
||||
mockLCProject(lc, aaa.getName());
|
||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||
assertEquals(0, manager.getOpenLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
public void testLaunchObjectAddedRemapping2() throws CoreException {
|
||||
projectMappingSetup();
|
||||
// test unmapping
|
||||
manager.launchObjectAdded(aaa);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
manager.launchObjectAdded(lc);
|
||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
manager.launchObjectAdded(aaa); // that would remove aaa mapping since lc is already there
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getLaunchDescriptors()[0].getName());
|
||||
assertEquals(2, manager.getOpenLaunchDescriptors().length); // XXX should be 1
|
||||
manager.launchObjectChanged(aaa);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getOpenLaunchDescriptors()[0].getName());
|
||||
manager.launchObjectRemoved(lc);
|
||||
assertEquals(0, manager.getOpenLaunchDescriptors().length); // XXX should be 1
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -490,9 +499,9 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
public void testLaunchObjectRemoved() throws CoreException {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(1, manager.getOpenLaunchDescriptors().length);
|
||||
manager.launchObjectRemoved(lc);
|
||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||
assertEquals(0, manager.getOpenLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -825,7 +834,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
ILaunchMode mode = mockLaunchModes(lctype, "foo")[0];
|
||||
manager.launchConfigurationAdded(lc);
|
||||
verify(provider).launchConfigurationAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
assertEquals(lc.getName(), launchDescriptors[0].getName());
|
||||
|
@ -844,7 +853,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
||||
manager.launchConfigurationAdded(lc2);
|
||||
verify(provider).launchConfigurationAdded(lc2);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
assertEquals(lc2.getName(), launchDescriptors[0].getName());
|
||||
|
@ -909,7 +918,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager = new FixedLaunchBarManager();
|
||||
targetType.targets.add(mytarget);
|
||||
manager.launchObjectAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
assertEquals(lc.getName(), launchDescriptors[0].getName());
|
||||
|
@ -933,7 +942,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
store.put("activeConfigDesc", desc.getId());
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertEquals(desc, launchDescriptors[0]);
|
||||
// assertEquals(desc, descriptor);
|
||||
|
@ -956,7 +965,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(0, launchDescriptors.length);
|
||||
}
|
||||
|
||||
|
@ -970,7 +979,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(descType.getId() + "somestuff").when(element).getAttribute("id");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(0, launchDescriptors.length);
|
||||
}
|
||||
|
||||
|
@ -986,7 +995,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
assertEquals(desc, manager.getLaunchDescriptors()[0]);
|
||||
assertEquals(desc, manager.getOpenLaunchDescriptors()[0]);
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorTypeNoPrio() throws CoreException {
|
||||
|
@ -1000,7 +1009,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
assertEquals(desc, manager.getLaunchDescriptors()[0]);
|
||||
assertEquals(desc, manager.getOpenLaunchDescriptors()[0]);
|
||||
}
|
||||
|
||||
public void testExtensionTargetType() throws CoreException {
|
||||
|
@ -1044,7 +1053,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
targetType.targets.add(mytarget);
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertEquals(desc, launchDescriptors[0]);
|
||||
assertEquals(mytarget, manager.getActiveLaunchTarget());
|
||||
|
|
|
@ -12,11 +12,9 @@ package org.eclipse.cdt.launchbar.core;
|
|||
|
||||
/**
|
||||
* Convenience implementation of ILaunchDescriptor
|
||||
*
|
||||
* @author elaskavaia
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractLaunchDescriptor implements ILaunchDescriptor {
|
||||
private boolean open = true;
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
@ -46,4 +44,13 @@ public abstract class AbstractLaunchDescriptor implements ILaunchDescriptor {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void setOpen(boolean open) {
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Schaefer
|
||||
* Alena Laskavaia - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ import org.eclipse.debug.core.ILaunchMode;
|
|||
|
||||
public interface ILaunchBarManager extends IAdaptable {
|
||||
|
||||
ILaunchDescriptor[] getLaunchDescriptors() throws CoreException;
|
||||
ILaunchDescriptor[] getLaunchDescriptors();
|
||||
|
||||
ILaunchDescriptor[] getOpenLaunchDescriptors();
|
||||
|
||||
ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException;
|
||||
|
||||
|
@ -52,6 +54,8 @@ public interface ILaunchBarManager extends IAdaptable {
|
|||
|
||||
ILaunchDescriptor launchObjectChanged(Object element) throws CoreException;
|
||||
|
||||
ILaunchDescriptor getLaunchDescriptor(Object element);
|
||||
|
||||
interface Listener {
|
||||
|
||||
void activeConfigurationDescriptorChanged();
|
||||
|
|
|
@ -37,4 +37,9 @@ public interface ILaunchDescriptor {
|
|||
*/
|
||||
ILaunchDescriptorType getType();
|
||||
|
||||
/**
|
||||
* Descriptor considered open when it is visible to user, and closed otherwise
|
||||
*/
|
||||
boolean isOpen();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems 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:
|
||||
* Alena Laskavaia - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
/**
|
||||
* Project Based launch descriptor knows about project it is associated with
|
||||
*/
|
||||
public interface ILaunchDescriptorProjectBased extends ILaunchDescriptor {
|
||||
/**
|
||||
* Get associate project
|
||||
*/
|
||||
public abstract IProject getProject();
|
||||
}
|
|
@ -1,16 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
* Copyright (c) 2014 QNX Software Systems 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
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
* Contributors:
|
||||
* Alena Laskavaia - Initial API and implementationn
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
|
|
|
@ -1,45 +1,46 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
* Copyright (c) 2014 QNX Software Systems 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
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
* Contributors:
|
||||
* Alena Laskavaia - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public class ProjectBasedLaunchDescriptor extends ConfigBasedLaunchDescriptor {
|
||||
public class ProjectBasedLaunchDescriptor extends ConfigBasedLaunchDescriptor implements ILaunchDescriptorProjectBased {
|
||||
private IProject project;
|
||||
|
||||
public ProjectBasedLaunchDescriptor(ILaunchDescriptorType type, IProject p, ILaunchConfiguration lc) {
|
||||
super(type, lc);
|
||||
if (p == null)
|
||||
throw new NullPointerException();
|
||||
this.project = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (getLaunchConfiguration() == null)
|
||||
return project.getName();
|
||||
else
|
||||
return getLaunchConfiguration().getName();
|
||||
ILaunchConfiguration lc = getLaunchConfiguration();
|
||||
if (lc != null)
|
||||
return lc.getName();
|
||||
return project.getName();
|
||||
}
|
||||
|
||||
public IProject getProject() {
|
||||
@Override
|
||||
public IProject getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (getLaunchConfiguration() == null)
|
||||
return getName();
|
||||
return "LC/" + getName();
|
||||
ILaunchConfiguration lc = getLaunchConfiguration();
|
||||
if (lc != null)
|
||||
return "LC/" + lc.getName();
|
||||
return "P/" + project.getName();
|
||||
}
|
||||
}
|
|
@ -1,22 +1,16 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
* Copyright (c) 2014 QNX Software Systems 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
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
* Contributors:
|
||||
* Alena Laskavaia - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.internal.Activator;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunchDescriptorType {
|
||||
|
@ -28,11 +22,18 @@ public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunch
|
|||
public boolean ownsLaunchObject(Object element) {
|
||||
if (super.ownsLaunchObject(element))
|
||||
return true;
|
||||
if (element instanceof IProject && ownsProject((IProject) element))
|
||||
if (element instanceof IProject && ((IProject) element).isOpen() && ownsProject((IProject) element))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean ownsLaunchDescriptor(ILaunchDescriptor ld) {
|
||||
if (!(ld instanceof ProjectBasedLaunchDescriptorType))
|
||||
return false;
|
||||
ProjectBasedLaunchDescriptorType other = (ProjectBasedLaunchDescriptorType) ld;
|
||||
return other.getLaunchConfigurationType().equals(getLaunchConfigurationType());
|
||||
}
|
||||
|
||||
protected abstract boolean ownsProject(IProject element);
|
||||
|
||||
@Override
|
||||
|
@ -40,24 +41,44 @@ public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunch
|
|||
if (element instanceof ILaunchConfiguration) {
|
||||
ILaunchConfiguration llc = (ILaunchConfiguration) element;
|
||||
IProject project = getProject(llc);
|
||||
// TODO we need disable project based descriptor here
|
||||
return new ProjectBasedLaunchDescriptor(this, project, llc);
|
||||
} else if (element instanceof IProject) {
|
||||
try {
|
||||
ILaunchDescriptor[] lds = getManager().getLaunchDescriptors();
|
||||
for (int i = 0; i < lds.length; i++) {
|
||||
ILaunchDescriptor ld = lds[i];
|
||||
if (ld instanceof ProjectBasedLaunchDescriptor
|
||||
&& element.equals(((ProjectBasedLaunchDescriptor) ld).getProject())) {
|
||||
return null; // somebody else has it
|
||||
}
|
||||
// this type creates two versions of the descriptor - launch config based
|
||||
// and project based. Project based do not have a config. If at least one
|
||||
// launch config created, associated with same project, we don't need descriptor with null config
|
||||
// anymore so we return null in this case
|
||||
IProject project = (IProject) element;
|
||||
ProjectBasedLaunchDescriptor desc = new ProjectBasedLaunchDescriptor(this, project, null);
|
||||
ILaunchDescriptor[] lds = getManager().getLaunchDescriptors();
|
||||
for (int i = 0; i < lds.length; i++) {
|
||||
ILaunchDescriptor ld = lds[i];
|
||||
if (isBetter(ld, desc)) {
|
||||
return null;// there is a better descriptor already
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
return new ProjectBasedLaunchDescriptor(this, (IProject) element, null);
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true is a is better then b (which would eliminate b)
|
||||
*/
|
||||
protected boolean isBetter(ILaunchDescriptor a, ILaunchDescriptor b) {
|
||||
if (a instanceof ProjectBasedLaunchDescriptor && b instanceof ProjectBasedLaunchDescriptor) {
|
||||
ProjectBasedLaunchDescriptor pa = (ProjectBasedLaunchDescriptor) a;
|
||||
ProjectBasedLaunchDescriptor pb = (ProjectBasedLaunchDescriptor) b;
|
||||
if (pb.getProject().equals(pa.getProject())
|
||||
&& pa.getLaunchConfigurationType().equals(pb.getLaunchConfigurationType())
|
||||
&& pa.getLaunchConfiguration() != null
|
||||
&& pb.getLaunchConfiguration() == null) {
|
||||
// a is for same project and same type, but actually have non-null configuraton
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract IProject getProject(ILaunchConfiguration llc);
|
||||
}
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -60,7 +61,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
private ILaunchDescriptor activeLaunchDesc;
|
||||
private ILaunchMode activeLaunchMode;
|
||||
private ILaunchTarget activeLaunchTarget;
|
||||
|
||||
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||
|
@ -71,10 +71,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
IEclipsePreferences store = getPreferenceStore();
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, Collections.EMPTY_LIST.toString());
|
||||
|
||||
|
||||
loadExtensions();
|
||||
|
||||
// Hook up the existing launch configurations and listen
|
||||
ILaunchManager launchManager = getLaunchManager();
|
||||
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
||||
|
@ -83,16 +80,19 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
launchManager.addLaunchConfigurationListener(this);
|
||||
reorderDescriptors(configDescIds);
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
ILaunchDescriptor configDesc = getDescriptorById(activeConfigDescId);
|
||||
if (configDesc == null) {
|
||||
configDesc = getLastUsedDescriptor();
|
||||
}
|
||||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
|
||||
|
||||
private ILaunchDescriptor getDescriptorById(String activeConfigDescId) {
|
||||
return descriptors.get(activeConfigDescId);
|
||||
}
|
||||
|
||||
protected void loadExtensions() {
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
// first pass - targets and descriptors
|
||||
for (IExtension extension : extensions) {
|
||||
|
@ -156,7 +156,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.log(e); // exceptions during extension loading, log and move on
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// third pass - object providers
|
||||
for (IExtension extension : extensions) {
|
||||
|
@ -172,9 +171,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void reorderDescriptors(String configDescIds) {
|
||||
configDescIds = configDescIds.replaceAll("[\\]\\[]", "");
|
||||
|
@ -182,7 +179,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
for (int i = 0; i < split.length; i++) {
|
||||
String string = split[i];
|
||||
String id = string.trim();
|
||||
ILaunchDescriptor desc = descriptors.get(id);
|
||||
ILaunchDescriptor desc = getDescriptorById(id);
|
||||
if (desc != null) {
|
||||
descriptors.remove(id);
|
||||
descriptors.put(id, desc);
|
||||
|
@ -314,9 +311,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
// new object causes re-set of active descriptor too
|
||||
setActiveLaunchDescriptor(desc);
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor launchObjectAdded(Object element) {
|
||||
|
@ -328,6 +325,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
return remapLaunchObject(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getLaunchDescriptor(Object element) {
|
||||
return objectDescriptorMap.get(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor launchObjectChanged(Object element) {
|
||||
Activator.trace("launch object changed " + element);
|
||||
|
@ -366,20 +368,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
return descs[descs.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor[] getOpenLaunchDescriptors() {
|
||||
ArrayList<ILaunchDescriptor> values = new ArrayList<>(descriptors.values());
|
||||
for (Iterator<ILaunchDescriptor> iterator = values.iterator(); iterator.hasNext();) {
|
||||
ILaunchDescriptor d = iterator.next();
|
||||
if (!d.isOpen())
|
||||
iterator.remove();
|
||||
}
|
||||
Collections.reverse(values);
|
||||
return values.toArray(new ILaunchDescriptor[values.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor[] getLaunchDescriptors() {
|
||||
// return descriptor in usage order (most used first). UI can sort them later as it wishes
|
||||
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
|
||||
// reverse
|
||||
for (int i = 0; i < descs.length / 2; i++) {
|
||||
ILaunchDescriptor ld = descs[i];
|
||||
int j = descs.length - 1 - i;
|
||||
descs[i] = descs[j];
|
||||
descs[j] = ld;
|
||||
}
|
||||
return descs;
|
||||
ArrayList<ILaunchDescriptor> values = new ArrayList<>(descriptors.values());
|
||||
Collections.reverse(values);
|
||||
return values.toArray(new ILaunchDescriptor[values.size()]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getActiveLaunchDescriptor() {
|
||||
return activeLaunchDesc;
|
||||
|
@ -400,7 +409,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
if (configDesc == null)
|
||||
configDesc = getLastUsedDescriptor(); // do not set to null unless no descriptors
|
||||
activeLaunchDesc = configDesc;
|
||||
|
||||
if (configDesc != null) { // keeps most used descriptor last
|
||||
descriptors.remove(configDesc.getId());
|
||||
descriptors.put(configDesc.getId(), configDesc);
|
||||
|
@ -409,7 +417,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||
Activator.trace("new active config is stored " + configDesc);
|
||||
setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, descriptors.keySet().toString());
|
||||
|
||||
// Send notifications
|
||||
updateLaunchDescriptor(activeLaunchDesc);
|
||||
// Set active target
|
||||
|
@ -426,9 +433,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
// checking active target
|
||||
if (activeLaunchTarget != null && supportsTargetType(activeLaunchDesc, activeLaunchTarget.getType()))
|
||||
return; // not changing target
|
||||
|
||||
// last stored target from persistent storage
|
||||
String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
ILaunchTarget storedTarget = getLaunchTarget(activeTargetId);
|
||||
if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget.getType())) {
|
||||
setActiveLaunchTarget(storedTarget);
|
||||
|
@ -436,14 +442,14 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
// default target for descriptor
|
||||
setActiveLaunchTarget(getDeafultLaunchTarget(activeLaunchDesc));
|
||||
}
|
||||
}
|
||||
|
||||
protected void syncActiveMode() {
|
||||
if (activeLaunchDesc == null) {
|
||||
setActiveLaunchMode(null);
|
||||
return;
|
||||
}
|
||||
ILaunchMode foundMode = null;
|
||||
ILaunchMode foundMode = null;
|
||||
String storedModeId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_MODE, null); // last desc mode id
|
||||
String lastActiveModeId = activeLaunchMode == null ? null : activeLaunchMode.getIdentifier();
|
||||
ILaunchMode[] supportedModes = getLaunchModes(); // this is based on active desc and target which are already set
|
||||
|
@ -462,7 +468,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
}
|
||||
setActiveLaunchMode(foundMode);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supportsMode(ILaunchMode mode) {
|
||||
// check that active descriptor supports the given mode
|
||||
|
@ -497,9 +503,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
protected IEclipsePreferences getPreferenceStore() {
|
||||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
}
|
||||
|
||||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
for (Listener listener : listeners) {
|
||||
|
@ -603,7 +609,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
setPreference(getPerDescriptorStore(),
|
||||
PREF_ACTIVE_LAUNCH_TARGET, target.getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateLaunchTarget(ILaunchTarget target) {
|
||||
for (Listener listener : listeners) {
|
||||
|
@ -744,4 +750,16 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
|
||||
// Nothing to do on changes
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
ILaunchManager launchManager = getLaunchManager();
|
||||
launchManager.removeLaunchConfigurationListener(this);
|
||||
for (ILaunchObjectProvider o : objectProviders) {
|
||||
try {
|
||||
o.dispose();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems 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:
|
||||
* Doug Schaefer - Initial API and implementation
|
||||
* Alena Laskavaia
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
|
@ -14,13 +25,11 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
|
||||
|
||||
private ILaunchBarManager manager;
|
||||
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) {
|
||||
this.manager = manager;
|
||||
|
||||
try {
|
||||
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
|
||||
manager.launchObjectAdded(project);
|
||||
|
@ -28,7 +37,6 @@ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IReso
|
|||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
|
||||
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
|
||||
}
|
||||
|
||||
|
@ -45,12 +53,14 @@ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IReso
|
|||
public boolean visit(IResourceDelta delta) throws CoreException {
|
||||
IResource res = delta.getResource();
|
||||
if (res instanceof IProject) {
|
||||
IProject project = (IProject) delta.getResource();
|
||||
IProject project = (IProject) res;
|
||||
int kind = delta.getKind();
|
||||
if ((kind & IResourceDelta.ADDED) != 0) {
|
||||
manager.launchObjectAdded(project);
|
||||
} else if ((kind & IResourceDelta.REMOVED) != 0) {
|
||||
manager.launchObjectRemoved(project);
|
||||
} else if ((kind & IResourceDelta.CHANGED) != 0) {
|
||||
manager.launchObjectChanged(project);
|
||||
}
|
||||
return false;
|
||||
} else if (res instanceof IFile || res instanceof IFolder) {
|
||||
|
@ -63,5 +73,4 @@ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IReso
|
|||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,28 +82,24 @@ public class ConfigSelector extends CSelector {
|
|||
}
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
try {
|
||||
ILaunchDescriptor[] descs = getManager().getLaunchDescriptors();
|
||||
if (descs.length > 0) {
|
||||
if (descs.length > SEPARATOR_INDEX + 1) {
|
||||
ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length];
|
||||
System.arraycopy(descs, 0, descsCopy, 0, SEPARATOR_INDEX); // copy first 3 elements
|
||||
System.arraycopy(descs, 0, descsCopy, SEPARATOR_INDEX, descs.length); // copy all into rest
|
||||
// sort rest
|
||||
Arrays.sort(descsCopy, SEPARATOR_INDEX, descsCopy.length, new Comparator<ILaunchDescriptor>() {
|
||||
@Override
|
||||
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
return descsCopy;
|
||||
} else
|
||||
return descs;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
ILaunchDescriptor[] descs = getManager().getOpenLaunchDescriptors();
|
||||
if (descs.length > 0) {
|
||||
if (descs.length > SEPARATOR_INDEX + 1) {
|
||||
ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length];
|
||||
System.arraycopy(descs, 0, descsCopy, 0, SEPARATOR_INDEX); // copy first 3 elements
|
||||
System.arraycopy(descs, 0, descsCopy, SEPARATOR_INDEX, descs.length); // copy all into rest
|
||||
// sort rest
|
||||
Arrays.sort(descsCopy, SEPARATOR_INDEX, descsCopy.length, new Comparator<ILaunchDescriptor>() {
|
||||
@Override
|
||||
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
return descsCopy;
|
||||
} else
|
||||
return descs;
|
||||
}
|
||||
return noConfigs;
|
||||
return noConfigs;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue