javafx: open .fxml in SceneBuilder

This commit is contained in:
anna
2013-02-14 13:56:03 +01:00
parent fec2cc5e21
commit ffeaa8c21f
6 changed files with 297 additions and 3 deletions
@@ -17,6 +17,13 @@
<localInspection language="XML" shortName="JavaFxDefaultTag" displayName="Unnecessary default tag" groupName="JavaFX"
enabledByDefault="true" level="WARNING" implementationClass="org.jetbrains.plugins.javaFX.fxml.codeInsight.inspections.JavaFxDefaultTagInspection"/>
<applicationService serviceInterface="org.jetbrains.plugins.javaFX.JavaFxSettings" serviceImplementation="org.jetbrains.plugins.javaFX.JavaFxSettings"/>
<applicationConfigurable instance="org.jetbrains.plugins.javaFX.JavaFxSettingsConfigurable"/>
</extensions>
<actions>
<action class="org.jetbrains.plugins.javaFX.actions.OpenInSceneBuilderAction" id="OpenInSceneBuilder" text="Open In SceneBuilder">
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
</action>
</actions>
</idea-plugin>
@@ -0,0 +1,56 @@
/*
* Copyright 2000-2013 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 org.jetbrains.plugins.javaFX;
import com.intellij.openapi.components.*;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.Nullable;
/**
* User: anna
* Date: 2/14/13
*/
@State(
name="JavaFxSettings",
storages = {
@Storage(
file = StoragePathMacros.APP_CONFIG + "/other.xml"
)}
)
public class JavaFxSettings implements PersistentStateComponent<JavaFxSettings> {
public String myPathToSceneBuilder = null;
public static JavaFxSettings getInstance() {
return ServiceManager.getService(JavaFxSettings.class);
}
public JavaFxSettings getState() {
return this;
}
public void loadState(JavaFxSettings object) {
XmlSerializerUtil.copyBean(object, this);
}
@Nullable
public String getPathToSceneBuilder() {
return myPathToSceneBuilder;
}
public void setPathToSceneBuilder(String pathToSceneBuilder) {
myPathToSceneBuilder = pathToSceneBuilder;
}
}
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.javaFX.JavaFxSettingsConfigurable.JavaFxConfigurablePanel">
<grid id="27dc6" binding="myWholePanel" layout-manager="GridBagLayout">
<constraints>
<xy x="20" y="389" width="500" height="36"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="81eb4" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<labelFor value="539ac"/>
<text value="&amp;Path to SceneBuilder:"/>
</properties>
</component>
<vspacer id="439f6">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="1.0"/>
</constraints>
</vspacer>
<component id="539ac" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myPathField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
@@ -0,0 +1,123 @@
/*
* Copyright 2000-2013 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 org.jetbrains.plugins.javaFX;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* User: anna
* Date: 2/14/13
*/
public class JavaFxSettingsConfigurable implements SearchableConfigurable, Configurable.NoScroll {
private final JavaFxSettings mySettings;
private JavaFxConfigurablePanel myPanel;
public JavaFxSettingsConfigurable(JavaFxSettings settings) {
mySettings = settings;
}
@Nls
@Override
public String getDisplayName() {
return "JavaFX";
}
@Nullable
@Override
public String getHelpTopic() {
return "preferences.JavaFX";
}
@Nullable
@Override
public JComponent createComponent() {
myPanel = new JavaFxConfigurablePanel();
return myPanel.myWholePanel;
}
@Override
public boolean isModified() {
return myPanel.isModified(mySettings);
}
@Override
public void apply() throws ConfigurationException {
myPanel.apply(mySettings);
}
@Override
public void reset() {
myPanel.reset(mySettings);
}
@Override
public void disposeUIResources() {
myPanel = null;
}
@NotNull
@Override
public String getId() {
return getHelpTopic();
}
@Nullable
@Override
public Runnable enableSearch(String option) {
return null;
}
public static class JavaFxConfigurablePanel {
private TextFieldWithBrowseButton myPathField;
private JPanel myWholePanel;
public JavaFxConfigurablePanel() {
myPathField.addBrowseFolderListener("SceneBuilder Configuration", "Select path to SceneBuilder executable", null,
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
private void reset(JavaFxSettings settings) {
final String pathToSceneBuilder = settings.getPathToSceneBuilder();
if (pathToSceneBuilder != null) {
myPathField.setText(FileUtil.toSystemDependentName(pathToSceneBuilder));
}
}
private void apply(JavaFxSettings settings) {
settings.setPathToSceneBuilder(FileUtil.toSystemIndependentName(myPathField.getText()));
}
private boolean isModified(JavaFxSettings settings) {
final String pathToSceneBuilder = settings.getPathToSceneBuilder();
return !Comparing.strEqual(FileUtil.toSystemIndependentName(myPathField.getText().trim()),
pathToSceneBuilder != null ? pathToSceneBuilder.trim() : null);
}
}
}
@@ -0,0 +1,73 @@
/*
* Copyright 2000-2013 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 org.jetbrains.plugins.javaFX.actions;
import com.intellij.CommonBundle;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.plugins.javaFX.JavaFxSettings;
import org.jetbrains.plugins.javaFX.fxml.JavaFxFileTypeFactory;
/**
* User: anna
* Date: 2/14/13
*/
public class OpenInSceneBuilderAction extends AnAction {
private static final Logger LOG = Logger.getInstance("#" + OpenInSceneBuilderAction.class.getName());
@Override
public void actionPerformed(AnActionEvent e) {
final VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
LOG.assertTrue(virtualFile != null);
final String path = virtualFile.getPath();
final String pathToSceneBuilder = JavaFxSettings.getInstance().getPathToSceneBuilder();
LOG.assertTrue(pathToSceneBuilder != null);
final GeneralCommandLine commandLine = new GeneralCommandLine();
try {
commandLine.setExePath(FileUtil.toSystemDependentName(pathToSceneBuilder));
commandLine.addParameter(path);
commandLine.createProcess();
}
catch (ExecutionException ex) {
Messages.showErrorDialog("Failed to start SceneBuilder: " + commandLine.getCommandLineString(), CommonBundle.getErrorTitle());
}
}
@Override
public void update(AnActionEvent e) {
final Presentation presentation = e.getPresentation();
presentation.setEnabled(false);
presentation.setVisible(false);
final VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
if (virtualFile != null &&
JavaFxFileTypeFactory.isFxml(virtualFile) &&
!StringUtil.isEmptyOrSpaces(JavaFxSettings.getInstance().getPathToSceneBuilder())) {
presentation.setEnabled(true);
presentation.setVisible(true);
}
}
}
@@ -15,12 +15,12 @@ import org.jetbrains.annotations.NotNull;
public class JavaFxFileTypeFactory extends FileTypeFactory {
public static final String FXML_EXTENSION = "fxml";
public static boolean isFxml(PsiFile file) {
public static boolean isFxml(@NotNull PsiFile file) {
final VirtualFile virtualFile = file.getViewProvider().getVirtualFile();
return isFxml(virtualFile);
}
public static boolean isFxml(VirtualFile virtualFile) {
public static boolean isFxml(@NotNull VirtualFile virtualFile) {
final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(FXML_EXTENSION);
return virtualFile.getFileType() == fileType && FXML_EXTENSION.equals(virtualFile.getExtension());
}