Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
AbstractExplorer can have links instead of tree (fixes #2003)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal committed Mar 13, 2019
1 parent 36c8d12 commit 59e55d2
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* Copyright (c) 2017-2019 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -16,7 +16,10 @@

import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.common.wait.WaitWhile;
import org.eclipse.reddeer.core.condition.WidgetIsFound;
import org.eclipse.reddeer.core.matcher.WithTextMatcher;
import org.eclipse.reddeer.eclipse.core.resources.AbstractProject;
import org.eclipse.reddeer.eclipse.core.resources.DefaultProject;
import org.eclipse.reddeer.eclipse.core.resources.DefaultProjectItem;
Expand All @@ -40,6 +43,7 @@
*
* @author Jiri Peterka
* @author mlabuda@redhat.com
* @author Ondrej Dockal, odockal@redhat.com
*
*/
public class AbstractExplorer extends WorkbenchView {
Expand Down Expand Up @@ -75,8 +79,8 @@ public void selectAllProjects(){
for (DefaultProject project: projects) {
projectsItems.add(project.getTreeItem());
}
getTree().selectItems(projectsItems.toArray(new TreeItem[projectsItems.size()]));
}
getTree().selectItems(projectsItems.toArray(new TreeItem[projectsItems.size()]));
}

/**
Expand Down Expand Up @@ -106,7 +110,8 @@ public List<DefaultProject> getProjects(){

TreeViewerHandler treeViewerHandler = TreeViewerHandler.getInstance();

for (TreeItem item : getTree().getItems()){

for (TreeItem item : getExplorerTreeItems()){
String projectName = treeViewerHandler.getNonStyledText(item);
log.debug("Getting project with name "+projectName);
if (org.eclipse.reddeer.direct.project.Project.isProject(projectName)) {
Expand All @@ -123,7 +128,7 @@ public List<DefaultProject> getProjects(){
public List<ProjectItem> getProjectItems() {
List<ProjectItem> items = new ArrayList<ProjectItem>();

for (TreeItem item : getTree().getItems()) {
for (TreeItem item : getExplorerTreeItems()) {
items.add(new DefaultProjectItem(item));
}
return items;
Expand Down Expand Up @@ -196,7 +201,7 @@ public DefaultProject getProject(String projectName){
* @return project of specific type with defined name
*/
public <T extends AbstractProject> T getProject(final String projectName, Class<T> projectType) {
for (TreeItem item : getTree().getItems()){
for (TreeItem item : getExplorerTreeItems()){
try {
T project = projectType.getDeclaredConstructor(TreeItem.class).newInstance(item);
if (project.getName().equals(projectName)) {
Expand All @@ -214,4 +219,24 @@ public <T extends AbstractProject> T getProject(final String projectName, Class<
throw new EclipseLayerException("Required project does not exist. Make sure you are using correct project type"
+ " and desired project exists.");
}

/**
* Since 2019-03 Eclipse there is text and link in package/project explorer views when no project available
* https://github.com/eclipse/reddeer/issues/2003
* @returns list of TreeItem objects if there is any Tree available in explorer view,
* if there are link for creating or import new project into workspace, it returns an empty list.
*/
private List<TreeItem> getExplorerTreeItems() {
List<TreeItem> items = new ArrayList<TreeItem>();

WidgetIsFound widget = new WidgetIsFound(
org.eclipse.ui.forms.widgets.Hyperlink.class,
cTabItem.getControl(),
new WithTextMatcher("Create a project..."));
new WaitUntil(widget, TimePeriod.SHORT, false);
if (widget.getResult() != null) {
return items;
}
return getTree().getItems();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* Copyright (c) 2017-2019 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -11,8 +11,14 @@
*******************************************************************************/
package org.eclipse.reddeer.eclipse.test.ui.navigator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.eclipse.reddeer.eclipse.exception.EclipseLayerException;
import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand All @@ -21,9 +27,41 @@ public class ProjectExplorerTest {

private ProjectExplorer projectExplorer;

@Before
public void before() {
projectExplorer = new ProjectExplorer();
}

@After
public void after() {
projectExplorer.close();
}

@Test
public void open() {
projectExplorer = new ProjectExplorer();
projectExplorer.open();
}

@Test
public void getEmptyListOfProjects() {
projectExplorer.open();
assertEquals(projectExplorer.getProjects().size(), 0);
}

@Test
public void selectAllWithEmptyExplorer() {
projectExplorer.open();
try {
projectExplorer.selectAllProjects();
} catch (Exception exc) {
exc.printStackTrace();
fail("Selecting all projects when there is none should do nothing, not throw an exception: " + exc.getCause() + " " + exc.getMessage());
}
}

@Test(expected=EclipseLayerException.class)
public void selectProjectWithEmptyExplorer() {
projectExplorer.open();
projectExplorer.selectProjects("non-existing-project");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*******************************************************************************/
package org.eclipse.reddeer.gef.test;

import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.eclipse.condition.ProjectExists;
import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.reddeer.gef.GEFLayerException;
import org.eclipse.reddeer.gef.editor.GEFEditor;
Expand Down Expand Up @@ -49,6 +52,10 @@ public static void maximizeWorkbenchShell() {
@Before
public void createProject() {
new GeneralProjectWizard().create(PROJECT_NAME);

new ProjectExplorer().open();
new WaitUntil(new ProjectExists(PROJECT_NAME), TimePeriod.MEDIUM, false);
new ProjectExplorer().getProject(PROJECT_NAME).select();
}

@After
Expand All @@ -58,9 +65,6 @@ public void deleteAllProjects() {

@Test
public void selectEditPartTest() {
new ProjectExplorer().open();
new ProjectExplorer().getProject(PROJECT_NAME).select();

ExampleWizard.createLogicDiagram("test");

GEFEditor gefEditor = new GEFEditor("test.logic");
Expand All @@ -77,9 +81,6 @@ public void selectEditPartTest() {

@Test
public void clickEditPartTest() {
new ProjectExplorer().open();
new ProjectExplorer().getProject(PROJECT_NAME).select();

ExampleWizard.createLogicDiagram("test");

GEFEditor gefEditor = new GEFEditor("test.logic");
Expand All @@ -103,9 +104,6 @@ public void clickEditPartTest() {

@Test(expected = GEFLayerException.class)
public void nonExistingEditPartTest() {
new ProjectExplorer().open();
new ProjectExplorer().getProject(PROJECT_NAME).select();

ExampleWizard.createLogicDiagram("test");

GEFEditor gefEditor = new GEFEditor("test.logic");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.eclipse.condition.ProjectExists;
import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.reddeer.gef.editor.GEFEditor;
import org.eclipse.reddeer.gef.test.wizard.ExampleWizard;
Expand All @@ -26,6 +29,7 @@
import org.eclipse.reddeer.swt.api.Menu;
import org.eclipse.reddeer.workbench.impl.shell.WorkbenchShell;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -46,18 +50,22 @@ public static void maximizeWorkbenchShell() {
new WorkbenchShell().maximize();
}

@Before
public void createProject() {
new GeneralProjectWizard().create(PROJECT_NAME);

new ProjectExplorer().open();
new WaitUntil(new ProjectExists(PROJECT_NAME), TimePeriod.MEDIUM, false);
new ProjectExplorer().getProject(PROJECT_NAME).select();
}

@After
public void deleteAllProjects() {
new CleanWorkspaceRequirement().fulfill();
}

@Test
public void logicDiagramTest() {
new GeneralProjectWizard().create(PROJECT_NAME);

new ProjectExplorer().open();
new ProjectExplorer().getProject(PROJECT_NAME).select();

ExampleWizard.createLogicDiagram("test");

GEFEditor gefEditor = new GEFEditor("test.logic");
Expand Down Expand Up @@ -104,11 +112,6 @@ public void logicDiagramTest() {

@Test
public void shapesDiagramTest() {
new GeneralProjectWizard().create(PROJECT_NAME);

new ProjectExplorer().open();
new ProjectExplorer().getProject(PROJECT_NAME).select();

ExampleWizard.createShapesDiagram("test");

GEFEditor gefEditor = new GEFEditor("test.shapes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
package org.eclipse.reddeer.graphiti.test;

import org.eclipse.reddeer.common.exception.TestFailureException;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.condition.ProjectExists;
import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard;
import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.reddeer.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
Expand Down Expand Up @@ -45,6 +48,7 @@ public static void maximizeWorkbenchShell() {
public void createProject() {
new GeneralProjectWizard().create(PROJECT_NAME);
new ProjectExplorer().open();
new WaitUntil(new ProjectExists(PROJECT_NAME), TimePeriod.MEDIUM, false);
new ProjectExplorer().getProject("test").select();
new TutorialDiagramWizard().create("test");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import org.eclipse.pde.core.target.LoadTargetDefinitionJob;
import org.eclipse.pde.internal.core.target.TargetPlatformService;
import org.eclipse.reddeer.common.exception.RedDeerException;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.condition.ProjectExists;
import org.eclipse.reddeer.eclipse.core.resources.DefaultProject;
import org.eclipse.reddeer.eclipse.jdt.ui.packageview.PackageExplorerPart;
import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard;
Expand Down Expand Up @@ -131,6 +134,7 @@ protected static void fillInWizard(NewMenuWizard wizard) {
protected DefaultProject getProject(String name) {
PackageExplorerPart explorer = new PackageExplorerPart();
explorer.open();
new WaitUntil(new ProjectExists(name), TimePeriod.MEDIUM, false);
DefaultProject project = null;
try {
project = explorer.getProject(name);
Expand Down

0 comments on commit 59e55d2

Please sign in to comment.