Skip to content

Commit

Permalink
CHE-4783 Initial splash should be smarter (eclipse-che#5961)
Browse files Browse the repository at this point in the history
* CHE-4783 Initial splash should be smarter

* CHE-4783 Initial splash should be smarter
  • Loading branch information
Vitaliy Guliy committed Aug 10, 2017
1 parent 338773b commit fa465cb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.actions;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

import org.eclipse.che.ide.CoreLocalizationConstant;
Expand All @@ -34,27 +35,28 @@
@Singleton
public class NavigateToFileAction extends AbstractPerspectiveAction {

private final NavigateToFilePresenter presenter;
private final Provider<NavigateToFilePresenter> navigateToFilePresenterProvider;

@Inject
public NavigateToFileAction(NavigateToFilePresenter presenter,
public NavigateToFileAction(Provider<NavigateToFilePresenter> navigateToFilePresenterProvider,
Resources resources,
CoreLocalizationConstant localizationConstant) {
super(singletonList(PROJECT_PERSPECTIVE_ID),
localizationConstant.actionNavigateToFileText(),
localizationConstant.actionNavigateToFileDescription(),
null,
resources.navigateToFile());
this.presenter = presenter;
this.navigateToFilePresenterProvider = navigateToFilePresenterProvider;
}

@Override
public void actionPerformed(ActionEvent e) {
presenter.showDialog();
navigateToFilePresenterProvider.get().showDialog();
}

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
event.getPresentation().setEnabledAndVisible(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.actions.CreateProjectAction;
import org.eclipse.che.ide.actions.ImportProjectAction;
import org.eclipse.che.ide.actions.NavigateToFileAction;
import org.eclipse.che.ide.actions.find.FindActionAction;
import org.eclipse.che.ide.api.ProductInfoDataProvider;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionEvent;
Expand Down Expand Up @@ -63,7 +65,10 @@
*/
public class EmptyEditorsPanel extends Composite implements ResourceChangedEvent.ResourceChangedHandler {

private static EmptyEditorsPanelUiBinder ourUiBinder = GWT.create(EmptyEditorsPanelUiBinder.class);
interface EmptyEditorsPanelUiBinder extends UiBinder<Widget, EmptyEditorsPanel> {}

private static EmptyEditorsPanelUiBinder uiBinder = GWT.create(EmptyEditorsPanelUiBinder.class);

protected final AppContext appContext;
private final ActionManager actionManager;
private final Provider<PerspectiveManager> perspectiveManagerProvider;
Expand All @@ -72,7 +77,11 @@ public class EmptyEditorsPanel extends Composite implements ResourceChangedEvent
private final CoreLocalizationConstant localizationConstant;

private final Map<String, Action> noFiles = new HashMap<>();

private final Map<String, Action> noProjects = new HashMap<>();

private final Map<String, Action> factoryActions = new HashMap<>();

@UiField
protected DivElement title;
@UiField
Expand All @@ -94,22 +103,28 @@ public EmptyEditorsPanel(ActionManager actionManager,
CoreLocalizationConstant localizationConstant,
NewFileAction newFileAction,
CreateProjectAction createProjectAction,
ImportProjectAction importProjectAction) {
ImportProjectAction importProjectAction,
FindActionAction findActionAction,
NavigateToFileAction navigateToFileAction
) {
this(actionManager, perspectiveManagerProvider, keyBindingAgent, appContext, localizationConstant, newFileAction,
createProjectAction, importProjectAction);


eventBus.addHandler(ResourceChangedEvent.getType(), this);
final SVGResource logo = productInfoDataProvider.getWaterMarkLogo();
if (nonNull(logo)) {
this.logo.appendChild(new SVGImage(logo).getSvgElement().getElement());
}

factoryActions.put(findActionAction.getTemplatePresentation().getText(), findActionAction);
factoryActions.put(navigateToFileAction.getTemplatePresentation().getText(), navigateToFileAction);

//Sometimes initialization of Create/Import Project actions are completed after the Empty editor page is rendered.
//In this case we need to wait when actions will be initialized.
Timer hoverToRenderTimer = new Timer() {
@Override
public void run() {
renderNoProjects();
render();
}
};
hoverToRenderTimer.schedule(500);
Expand Down Expand Up @@ -137,8 +152,7 @@ public EmptyEditorsPanel(ActionManager actionManager,

presentationFactory = new PresentationFactory();

Widget rootElement = ourUiBinder.createAndBindUi(this);
initWidget(rootElement);
initWidget(uiBinder.createAndBindUi(this));
}

@Override
Expand All @@ -153,18 +167,23 @@ public void onResourceChanged(ResourceChangedEvent event) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
updateOnProjectsChange();
render();
}
});

}

private void updateOnProjectsChange() {
if (appContext.getProjects().length != 0) {
renderNoFiles();
} else {
protected void render() {
if (appContext.getProjects() != null && appContext.getProjects().length == 0) {
renderNoProjects();
return;
}

if (appContext.getWorkspace().getAttributes().containsKey("factoryId")) {
renderFactoryActions();
return;
}

renderNoFiles();
}

protected void renderNoProjects() {
Expand All @@ -175,12 +194,15 @@ protected void renderNoFiles() {
render(localizationConstant.emptyStateNoFiles(), noFiles);
}

protected void renderFactoryActions() {
render(localizationConstant.emptyStateNoFiles(), factoryActions);
}

private void render(String title, Map<String, Action> actions) {
this.title.setInnerText(title);
container.removeAllChildren();
Element listElement = Elements.createElement("ul", new String[] {style.list()});


for (Map.Entry<String, Action> pair : actions.entrySet()) {
LIElement liElement = Elements.createLiElement();
liElement.appendChild(renderAction(pair.getKey(), pair.getValue()));
Expand Down Expand Up @@ -237,5 +259,4 @@ interface Css extends CssResource {
String actionLabel();
}

interface EmptyEditorsPanelUiBinder extends UiBinder<Widget, EmptyEditorsPanel> {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
border: 1px solid fontColor;
color: fontColor;
border-radius: 2px;
margin-left: 50px;
margin-left: 30px;
}

.actionLabel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.Timer;
import com.google.inject.Provider;
import com.google.web.bindery.event.shared.EventBus;

Expand Down Expand Up @@ -46,13 +47,17 @@ public EmptyTreePanel(ActionManager actionManager,
super(actionManager, perspectiveManagerProvider, keyBindingAgent, appContext, localizationConstant, newFileAction,
createProjectAction, importProjectAction);
eventBus.addHandler(ResourceChangedEvent.getType(), this);

root.getStyle().setTop(46, Style.Unit.PX);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

//Sometimes initialization of Create/Import Project actions are completed after the Empty editor page is rendered.
//In this case we need to wait when actions will be initialized.
new Timer() {
@Override
public void execute() {
public void run() {
renderNoProjects();
}
});
}.schedule(500);
}

@Override
Expand All @@ -66,4 +71,5 @@ public void execute() {
}
});
}

}

0 comments on commit fa465cb

Please sign in to comment.