extract WebBrowserBase

This commit is contained in:
Vladimir Krivosheev
2014-02-07 17:18:17 +01:00
parent a6892528d3
commit ddd555fd16
7 changed files with 107 additions and 84 deletions
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.UUID;
final class ConfigurableWebBrowser extends WebBrowser {
final class ConfigurableWebBrowser extends WebBrowserBase {
private boolean active;
private String path;
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.UUID;
final class CustomWebBrowser extends WebBrowser {
final class CustomWebBrowser extends WebBrowserBase {
private final Computable<String> pathComputable;
private final Icon icon;
private final String browserNotFoundMessage;
@@ -27,7 +27,7 @@ public class StartBrowserSettings {
}
@Nullable
@Attribute(value = "name", converter = WebBrowser.ReferenceConverter.class)
@Attribute(value = "name", converter = WebBrowserBase.ReferenceConverter.class)
public WebBrowser getBrowser() {
return myBrowser;
}
@@ -1,23 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.browsers;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.util.xmlb.Converter;
import com.intellij.xml.XmlBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,30 +7,14 @@ import javax.swing.*;
import java.util.UUID;
public abstract class WebBrowser {
protected @NotNull BrowserFamily family;
protected @NotNull String name;
private final UUID id;
protected WebBrowser(@NotNull UUID id, @NotNull BrowserFamily family, @NotNull String name) {
this.id = id;
this.family = family;
this.name = name;
}
@NotNull
public abstract String getName();
@NotNull
public String getName() {
return name;
}
public abstract UUID getId();
@NotNull
public final UUID getId() {
return id;
}
@NotNull
public BrowserFamily getFamily() {
return family;
}
public abstract BrowserFamily getFamily();
@NotNull
public abstract Icon getIcon();
@@ -57,41 +23,8 @@ public abstract class WebBrowser {
public abstract String getPath();
@NotNull
public String getBrowserNotFoundMessage() {
return XmlBundle.message("error.0.browser.path.not.specified", getName());
}
public abstract String getBrowserNotFoundMessage();
@Nullable
public BrowserSpecificSettings getSpecificSettings() {
return null;
}
@NotNull
public static WebBrowser createCustomBrowser(@NotNull BrowserFamily family,
@NotNull String name,
@NotNull UUID id,
@NotNull Icon icon,
@NotNull NullableComputable<String> pathComputable,
@Nullable String browserNotFoundMessage) {
return new CustomWebBrowser(id, family, name, icon, pathComputable, browserNotFoundMessage);
}
@Override
public String toString() {
return getName() + " (" + getPath() + ")";
}
public static final class ReferenceConverter extends Converter<WebBrowser> {
@Nullable
@Override
public WebBrowser fromString(@NotNull String value) {
return WebBrowserManager.getInstance().findBrowserById(value);
}
@NotNull
@Override
public String toString(@NotNull WebBrowser browser) {
return browser.getId().toString();
}
}
public abstract BrowserSpecificSettings getSpecificSettings();
}
@@ -0,0 +1,96 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.browsers;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.util.xmlb.Converter;
import com.intellij.xml.XmlBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.UUID;
public abstract class WebBrowserBase extends WebBrowser {
protected @NotNull BrowserFamily family;
protected @NotNull String name;
private final UUID id;
protected WebBrowserBase(@NotNull UUID id, @NotNull BrowserFamily family, @NotNull String name) {
this.id = id;
this.family = family;
this.name = name;
}
@Override
@NotNull
public String getName() {
return name;
}
@Override
@NotNull
public final UUID getId() {
return id;
}
@Override
@NotNull
public BrowserFamily getFamily() {
return family;
}
@Override
@NotNull
public String getBrowserNotFoundMessage() {
return XmlBundle.message("error.0.browser.path.not.specified", getName());
}
@Override
@Nullable
public BrowserSpecificSettings getSpecificSettings() {
return null;
}
@NotNull
public static WebBrowser createCustomBrowser(@NotNull BrowserFamily family,
@NotNull String name,
@NotNull UUID id,
@NotNull Icon icon,
@NotNull NullableComputable<String> pathComputable,
@Nullable String browserNotFoundMessage) {
return new CustomWebBrowser(id, family, name, icon, pathComputable, browserNotFoundMessage);
}
@Override
public String toString() {
return getName() + " (" + getPath() + ")";
}
public static final class ReferenceConverter extends Converter<WebBrowser> {
@Nullable
@Override
public WebBrowser fromString(@NotNull String value) {
return WebBrowserManager.getInstance().findBrowserById(value);
}
@NotNull
@Override
public String toString(@NotNull WebBrowser browser) {
return browser.getId().toString();
}
}
}
@@ -16,10 +16,7 @@
package com.intellij.ide.browsers.actions;
import com.intellij.ide.GeneralSettings;
import com.intellij.ide.browsers.OpenInBrowserRequest;
import com.intellij.ide.browsers.WebBrowser;
import com.intellij.ide.browsers.WebBrowserManager;
import com.intellij.ide.browsers.WebBrowserUrlProvider;
import com.intellij.ide.browsers.*;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
@@ -21,10 +21,7 @@ import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.util.ExecUtil;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.browsers.BrowserSettings;
import com.intellij.ide.browsers.BrowserSpecificSettings;
import com.intellij.ide.browsers.UrlOpener;
import com.intellij.ide.browsers.WebBrowser;
import com.intellij.ide.browsers.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.ShowSettingsUtil;