Skip to content

Commit

Permalink
IDE-4904 Upgrade Planner doc links are broken
Browse files Browse the repository at this point in the history
  • Loading branch information
DL-EthanSun authored and gamerson committed Dec 22, 2020
1 parent 1b2e0d3 commit 00d2dff
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 40 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public UpgradeStep(
}

_summary = summary;
_icon = imagePath;
_url = url;
_requirement = requirement;
_status = status;
Expand Down Expand Up @@ -292,7 +291,6 @@ public void setStatus(UpgradeStepStatus status) {

private List<UpgradeStep> _children = new ArrayList<>();
private String _commandId;
private String _icon;
private UpgradeStep _parentUpgradeStep;
private String _requirement;
private final ServiceTracker<UpgradePlanner, UpgradePlanner> _serviceTracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

package com.liferay.ide.upgrade.plan.ui.internal;

import com.liferay.ide.core.util.CoreUtil;
import com.liferay.ide.upgrade.plan.core.UpgradePlan;
import com.liferay.ide.upgrade.plan.core.UpgradePlanner;
import com.liferay.ide.upgrade.plan.core.UpgradeStep;
import com.liferay.ide.upgrade.plan.ui.UpgradeInfoProvider;
import com.liferay.ide.upgrade.plan.ui.util.UIUtil;

import java.util.List;
import java.util.stream.Stream;

import org.eclipse.jface.viewers.ISelection;
Expand All @@ -26,6 +31,8 @@
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -43,18 +50,30 @@
/**
* @author Terry Jia
* @author Gregory Amerson
* @author Ethan Sun
*/
public class UpgradePlanInfoPage extends Page implements ISelectionChangedListener {

public UpgradePlanInfoPage(IWorkbenchPart workbenchPart) {
_workbenchPart = workbenchPart;

Bundle bundle = FrameworkUtil.getBundle(UpgradePlanInfoPage.class);
Bundle upgradePlanInfoPageBundle = FrameworkUtil.getBundle(UpgradePlanInfoPage.class);

_upgradeInfoProviderServiceTracker = new ServiceTracker<>(
bundle.getBundleContext(), UpgradeInfoProvider.class, null);
upgradePlanInfoPageBundle.getBundleContext(), UpgradeInfoProvider.class, null);

_upgradeInfoProviderServiceTracker.open();

Bundle upgradePlannerBundle = FrameworkUtil.getBundle(UpgradePlanner.class);

_upgradePlannerServiceTracker = new ServiceTracker<>(
upgradePlannerBundle.getBundleContext(), UpgradePlanner.class, null);

_upgradePlannerServiceTracker.open();

UpgradePlanner upgradePlannerService = _upgradePlannerServiceTracker.getService();

_upgradePlan = upgradePlannerService.getCurrentUpgradePlan();
}

@Override
Expand All @@ -66,6 +85,61 @@ public void createControl(Composite parent) {
_browser = new Browser(_composite, SWT.BORDER);

_browser.setLayoutData(new GridData(GridData.FILL_BOTH));

List<UpgradeStep> upgradeStepList = _upgradePlan.getUpgradeSteps();

_browser.addLocationListener(
new LocationListener() {

@Override
public void changed(LocationEvent event) {
}

@Override
public void changing(LocationEvent event) {
String url = event.location;

if (!url.startsWith("about:blank") && !url.startsWith("http")) {
_browser.setUrl("about:blank");

String replacement = "";

if (CoreUtil.isWindows()) {
replacement = "about:";
}
else {
replacement = "file:///";
}

final String targetUrl = url.replaceFirst(replacement, "");

Stream<UpgradeStep> upgradeStepStream = upgradeStepList.stream();

upgradeStepStream.forEach(
upgradeStep -> {
List<UpgradeStep> childrenStepList = upgradeStep.getChildren();

Stream<UpgradeStep> childStepStream = childrenStepList.stream();

childStepStream.filter(
currentStep -> {
String stepUrl = currentStep.getUrl();

if (CoreUtil.isWindows()) {
stepUrl = stepUrl.replace('\\', '/');
}

return stepUrl.endsWith(targetUrl);
}
).findFirst(
).ifPresent(
UpgradePlanInfoPage.this::renderBrowser
);
});
}
}

});
}

@Override
Expand All @@ -91,6 +165,43 @@ public void init(IPageSite pageSite) {
selectionProvider.addSelectionChangedListener(this);
}

public void renderBrowser(Object element) {
Stream.of(
_upgradeInfoProviderServiceTracker.getServices(new UpgradeInfoProvider[0])
).filter(
upgradeInfoProvider -> upgradeInfoProvider.provides(element)
).findFirst(
).ifPresent(
upgradeInfoProvider -> {
Promise<String> detail = upgradeInfoProvider.getDetail(element);

detail.onResolve(
() -> UIUtil.async(
() -> {
try {
if (detail.getFailure() != null) {
_browser.setText("about:blank");
}
else {
String detailValue = detail.getValue();

if (detailValue.startsWith("https://") || detailValue.equals("about:blank")) {
_browser.setUrl(detailValue);
}
else {
_browser.setText(detailValue, true);
}
}

_composite.redraw();
}
catch (Exception e) {
}
}));
}
);
}

@Override
public void selectionChanged(SelectionChangedEvent selectionChangedEvent) {
if ((_browser == null) || _browser.isDisposed()) {
Expand All @@ -102,42 +213,7 @@ public void selectionChanged(SelectionChangedEvent selectionChangedEvent) {
if (selection instanceof StructuredSelection) {
StructuredSelection structuredSelection = (StructuredSelection)selection;

Object firstElement = structuredSelection.getFirstElement();

Stream.of(
_upgradeInfoProviderServiceTracker.getServices(new UpgradeInfoProvider[0])
).filter(
upgradeInfoProvider -> upgradeInfoProvider.provides(firstElement)
).findFirst(
).ifPresent(
upgradeInfoProvider -> {
Promise<String> detail = upgradeInfoProvider.getDetail(firstElement);

detail.onResolve(
() -> UIUtil.async(
() -> {
try {
if (detail.getFailure() != null) {
_browser.setText("about:blank");
}
else {
String detailValue = detail.getValue();

if (detailValue.startsWith("https://") || detailValue.equals("about:blank")) {
_browser.setUrl(detailValue);
}
else {
_browser.setText(detail.getValue(), true);
}
}

_composite.redraw();
}
catch (Exception e) {
}
}));
}
);
renderBrowser(structuredSelection.getFirstElement());
}
}

Expand All @@ -155,6 +231,8 @@ public void setMessage(String message) {
private Browser _browser;
private Composite _composite;
private final ServiceTracker<UpgradeInfoProvider, UpgradeInfoProvider> _upgradeInfoProviderServiceTracker;
private UpgradePlan _upgradePlan;
private final ServiceTracker<UpgradePlanner, UpgradePlanner> _upgradePlannerServiceTracker;
private IWorkbenchPart _workbenchPart;

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@
import org.eclipse.wst.server.core.ServerCore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* @author Gregory Amerson
*/
@Ignore
public class PortalSourceLookupTests
{
@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.ServerCore;
import org.junit.Ignore;
import org.junit.Test;

/**
* @author Simon Jiang
*/
@Ignore
public class ServerCustomSettingTests extends ServerCoreBase
{

Expand Down

0 comments on commit 00d2dff

Please sign in to comment.