Skip to content

Commit

Permalink
CHE-1207: add ability to configure library folder by using Project Wi…
Browse files Browse the repository at this point in the history
…zard

Signed-off-by: Valeriy Svydenko <vsvydenko@codenvy.com>
  • Loading branch information
Valeriy Svydenko committed May 30, 2016
1 parent ae4c552 commit 45b3425
Show file tree
Hide file tree
Showing 23 changed files with 229 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class JavaCommandPagePresenter implements JavaCommandPageView.ActionDelegate, CommandConfigurationPage<JavaCommandConfiguration> {
private final JavaCommandPageView view;
private final SelectNodePresenter selectNodePresenter;
private final AppContext appContext;
private final AppContext appContext;

private JavaCommandConfiguration editedConfiguration;
private String originCommandLine;
Expand Down Expand Up @@ -100,8 +100,12 @@ public void setMainClass(String path, String fqn) {
String relativePath = path.substring(path.indexOf(projectPath) + projectPath.length() + 1);

view.setMainClass(relativePath);
editedConfiguration.setCommandLine(editedConfiguration.getCommandLine().replace(editedConfiguration.getMainClass(),relativePath));
editedConfiguration.setCommandLine(editedConfiguration.getCommandLine().replace(editedConfiguration.getMainClassFqn(),fqn));

String commandLine = editedConfiguration.getCommandLine();
commandLine = commandLine.replace(editedConfiguration.getMainClass(), relativePath);
commandLine = commandLine.replace(' ' + editedConfiguration.getMainClassFqn(),' ' + fqn);
editedConfiguration.setCommandLine(commandLine);

editedConfiguration.setMainClass(relativePath);
listener.onDirtyStateChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class JavaCommandType implements CommandType {
private final CurrentProjectPathProvider currentProjectPathProvider;
private final SourcepathProvider sourcepathProvider;
private final OutputDirProvider outputDirProvider;
private final ClasspathProvider classpathProvider;
private final ClasspathProvider classpathProvider;
private final JavaCommandConfigurationFactory configurationFactory;
private final Collection<CommandConfigurationPage<? extends CommandConfiguration>> pages;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SelectNodePresenter implements SelectNodeView.ActionDelegate {
private final ProjectExplorerPresenter projectExplorerPresenter;
private final AppContext appContext;

private JavaCommandPagePresenter delegate;
private JavaCommandPagePresenter delegate;

@Inject
public SelectNodePresenter(SelectNodeView view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
@Singleton
public class SelectNodeViewImpl extends Window implements SelectNodeView {
private final JavaContentRootInterceptor javaContentRootInterceptor;
private final ClassNodeInterceptor classNodeInterceptor;
private final ClassNodeInterceptor classNodeInterceptor;

private Tree tree;
private ActionDelegate delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ interface DirtyStateListener {
*
* @param path
* path to node
* @param icon
* of the added node
*/
void addNode(String path, int kind, SVGResource icon);
void addNode(String path, int kind);

/** Removes selected node from the property page. */
void removeNode(String path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.JarNodeInterceptor;
import org.eclipse.che.ide.ext.java.shared.ClasspathEntryKind;
import org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto;
import org.vectomatic.dom.svg.ui.SVGResource;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -156,7 +155,7 @@ public boolean isPlainJava() {
}

@Override
public void addNode(String path, int kind, SVGResource icon) {
public void addNode(String path, int kind) {
if (categories.containsKey(path)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.SelectNodePresenter;
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.SourceFolderNodeInterceptor;
import org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto;
import org.vectomatic.dom.svg.ui.SVGResource;

import java.util.List;
import java.util.Map;
Expand All @@ -41,12 +40,12 @@
*/
@Singleton
public class SourceEntryPresenter extends AbstractClasspathPagePresenter implements SourceEntryView.ActionDelegate {
private final DtoFactory dtoFactory;
private final ClasspathContainer classpathContainer;
private final ClasspathResolver classpathResolver;
private final AppContext appContext;
private final SelectNodePresenter selectNodePresenter;
private final SourceEntryView view;
private final DtoFactory dtoFactory;
private final ClasspathContainer classpathContainer;
private final ClasspathResolver classpathResolver;
private final AppContext appContext;
private final SelectNodePresenter selectNodePresenter;
private final SourceEntryView view;

private boolean dirty;
private boolean isPlainJava;
Expand Down Expand Up @@ -146,7 +145,7 @@ public void clearData() {
}

@Override
public void addNode(String path, int kind, SVGResource icon) {
public void addNode(String path, int kind) {
if (categories.containsKey(path)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.ClasspathNodeInterceptor;
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.JarNodeInterceptor;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.vectomatic.dom.svg.ui.SVGResource;

import java.util.Collections;

Expand Down Expand Up @@ -76,10 +75,10 @@ public void show(ClasspathPagePresenter pagePresenter, ClasspathNodeInterceptor

/** {@inheritDoc} */
@Override
public void setSelectedNode(String path, SVGResource icon) {
public void setSelectedNode(String path) {
if (interceptor instanceof JarNodeInterceptor) {
path = WORKSPACE_PATH + path;
}
classpathPagePresenter.addNode(path, interceptor.getKind(), icon);
classpathPagePresenter.addNode(path, interceptor.getKind());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.che.ide.api.mvp.View;
import org.eclipse.che.ide.api.project.node.Node;
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.ClasspathNodeInterceptor;
import org.vectomatic.dom.svg.ui.SVGResource;

import java.util.List;

Expand All @@ -29,7 +28,7 @@ public interface SelectNodeView extends View<SelectNodeView.ActionDelegate> {
/** Needs for delegate some function into SelectPath view. */
interface ActionDelegate {
/** Sets selected node. */
void setSelectedNode(String path, SVGResource icon);
void setSelectedNode(String path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.che.ide.ext.java.client.JavaResources;
import org.eclipse.che.ide.ext.java.client.project.classpath.valueproviders.selectnode.interceptors.ClasspathNodeInterceptor;
import org.eclipse.che.ide.ext.java.client.project.interceptor.JavaContentRootInterceptor;
import org.eclipse.che.ide.ext.java.shared.ClasspathEntryKind;
import org.eclipse.che.ide.project.shared.NodesResources;
import org.eclipse.che.ide.ui.smartTree.KeyboardNavigationHandler;
import org.eclipse.che.ide.ui.smartTree.NodeLoader;
Expand All @@ -38,7 +37,6 @@
import org.eclipse.che.ide.ui.smartTree.UniqueKeyProvider;
import org.eclipse.che.ide.ui.smartTree.event.SelectionChangedEvent;
import org.eclipse.che.ide.ui.window.Window;
import org.vectomatic.dom.svg.ui.SVGResource;

import javax.validation.constraints.NotNull;
import java.util.HashSet;
Expand Down Expand Up @@ -187,16 +185,7 @@ private void acceptButtonClicked() {
return;
}
Node selectedNode = nodes.get(0);
SVGResource icon;
if (ClasspathEntryKind.SOURCE == interceptor.getKind()) {
icon = javaResources.sourceFolder();
} else if (selectedNode.getName().endsWith(".jar")) {
icon = javaResources.jarFileIcon();
} else {
icon = nodesResources.simpleFolder();
}

delegate.setSelectedNode(((HasStorablePath)selectedNode).getStorablePath(), icon);
delegate.setSelectedNode(((HasStorablePath)selectedNode).getStorablePath());

hide();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@
*/
@RunWith(MockitoJUnitRunner.class)
public class JavaCommandPagePresenterTest {
private static final String MAIN_CLASS_PATH = "/project/src/com/company/Main.java";
private static final String RELATIVE_MAIN_CLASS_PATH = "src/com/company/Main.java";
private static final String MAIN_CLASS_PATH = "/project/src/com/company/MainClass.java";
private static final String RELATIVE_MAIN_CLASS_PATH = "src/com/company/MainClass.java";
private static final String PROJECT_PATH = "/project";
private static final String MAIN_CLASS_FQN = "com.company.Main";
private static final String COMMAND_LINE = "command-line";
private static final String MAIN_CLASS_FQN = "com.company.MainClass";
private static final String COMMAND_LINE = "cd ${current.project.path} &&" +
"javac -classpath ${project.java.classpath}" +
"-sourcepath ${project.java.sourcepath} -d ${project" +
".java.output.dir} src/Main.java &&" +
"java -classpath ${project.java.classpath}${project.java.output.dir} Main";
private static final String NEW_COMMAND_LINE = "cd ${current.project.path} &&" +
"javac -classpath ${project.java.classpath}" +
"-sourcepath ${project.java.sourcepath} -d ${project" +
".java.output.dir} src/com/company/MainClass.java &&" +
"java -classpath ${project.java.classpath}${project.java.output.dir} com.company.MainClass";

@Mock
private JavaCommandPageView view;
Expand Down Expand Up @@ -133,4 +142,24 @@ public void mainClassShouldBeUpdated() throws Exception {

verify(listener).onDirtyStateChanged();
}

@Test
public void mainClassShouldBeUpdated2() throws Exception {
CommandConfigurationPage.DirtyStateListener listener = mock(CommandConfigurationPage.DirtyStateListener.class);
String oldMainClass = "src/Main.java";
String oldMainClassFqn = "Main";

when(configuration.getMainClass()).thenReturn(oldMainClass);
when(configuration.getMainClassFqn()).thenReturn(oldMainClassFqn);

presenter.setDirtyStateListener(listener);
presenter.resetFrom(configuration);
presenter.setMainClass(MAIN_CLASS_PATH, MAIN_CLASS_FQN);

verify(view).setMainClass(RELATIVE_MAIN_CLASS_PATH);
verify(configuration).setMainClass(RELATIVE_MAIN_CLASS_PATH);
verify(configuration).setCommandLine(NEW_COMMAND_LINE);

verify(listener).onDirtyStateChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public interface PlainJavaLocalizationConstant extends Messages {

@Key("source.folder.attribute.label.name")
String sourceFolderAttribute();

@Key("library.folder.attribute.label.name")
String libraryFolderAttribute();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar.WIZARD_MODE_KEY;
import static org.eclipse.che.ide.ext.java.shared.Constants.SOURCE_FOLDER;
import static org.eclipse.che.plugin.java.plain.shared.PlainJavaProjectConstants.DEFAULT_SOURCE_FOLDER_VALUE;
import static org.eclipse.che.plugin.java.plain.shared.PlainJavaProjectConstants.LIBRARY_FOLDER;

/**
* Presenter of the wizard page which configures Plain Java project.
Expand All @@ -42,6 +43,8 @@ class PlainJavaPagePresenter extends AbstractWizardPage<ProjectConfigDto> implem
private final PlainJavaPageView view;
private final SelectNodePresenter selectNodePresenter;

private boolean isSourceSelected;

@Inject
public PlainJavaPagePresenter(PlainJavaPageView view, SelectNodePresenter selectNodePresenter) {
super();
Expand Down Expand Up @@ -83,19 +86,32 @@ public void go(AcceptsOneWidget container) {
@Override
public void onCoordinatesChanged() {
setAttribute(SOURCE_FOLDER, view.getSourceFolder());
setAttribute(LIBRARY_FOLDER, view.getLibraryFolder());

validateCoordinates();
updateDelegate.updateControls();
}

@Override
public void onBrowseButtonClicked() {
public void onBrowseSourceButtonClicked() {
isSourceSelected = true;
selectNodePresenter.show(this, dataObject.getName());
}

@Override
public void onBrowseLibraryButtonClicked() {
isSourceSelected = false;
selectNodePresenter.show(this, dataObject.getName());
}

@Override
public void onNodeSelected(String path) {
view.setSourceFolder(path.substring(dataObject.getName().length() + 1));
int projectNameLength = dataObject.getName().length();
if (isSourceSelected) {
view.setSourceFolder(path.substring(projectNameLength + 1));
} else {
view.setLibraryFolder(path.substring(projectNameLength + 1));
}

onCoordinatesChanged();
}
Expand Down Expand Up @@ -124,10 +140,12 @@ private void updateView() {

view.changeBrowseBtnVisibleState(!isCreateWizard);
view.changeSourceFolderFieldState(isCreateWizard);
view.changeLibraryPanelVisibleState(!isCreateWizard);

Map<String, List<String>> attributes = dataObject.getAttributes();

view.setSourceFolder(attributes.get(SOURCE_FOLDER) == null ? "" : getAttribute(SOURCE_FOLDER));
view.setLibraryFolder(getAttribute(LIBRARY_FOLDER));
}

private void validateCoordinates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ interface PlainJavaPageView extends View<PlainJavaPageView.ActionDelegate> {
/** Sets value of the source folder attribute. */
void setSourceFolder(String value);

/** Returns value of the library folder attribute. */
String getLibraryFolder();

/** Sets value of the library folder attribute. */
void setLibraryFolder(String value);

/**
* Marks a field with information about source folder as empty.
*
Expand All @@ -43,6 +49,14 @@ interface PlainJavaPageView extends View<PlainJavaPageView.ActionDelegate> {
*/
void changeBrowseBtnVisibleState(boolean isVisible);

/**
* Sets whether Library folder panel is visible.
*
* @param isVisible
* <code>true</code> to show the object, <code>false</code> to hide it
*/
void changeLibraryPanelVisibleState(boolean isVisible);

/**
* Sets whether source folder field is enabled.
*
Expand All @@ -55,7 +69,10 @@ interface ActionDelegate {
/** Performs any actions appropriate in response to the user having changed on the fields. */
void onCoordinatesChanged();

/** Called when Browse button is clicked. */
void onBrowseButtonClicked();
/** Called when Browse button is clicked for choosing source folder. */
void onBrowseSourceButtonClicked();

/** Called when Browse button is clicked for choosing library folder. */
void onBrowseLibraryButtonClicked();
}
}
Loading

0 comments on commit 45b3425

Please sign in to comment.