diff --git a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml index 285b8c1dda17..cbae519679ba 100644 --- a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml +++ b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml @@ -17,6 +17,13 @@ - + + + + + + + + diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettings.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettings.java new file mode 100644 index 000000000000..df60a33294e1 --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettings.java @@ -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 { + 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; + } +} \ No newline at end of file diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.form b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.form new file mode 100644 index 000000000000..b1ac08be5b46 --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.form @@ -0,0 +1,35 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.java new file mode 100644 index 000000000000..57c1e00f4e34 --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxSettingsConfigurable.java @@ -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); + } + } +} diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/actions/OpenInSceneBuilderAction.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/actions/OpenInSceneBuilderAction.java new file mode 100644 index 000000000000..365adb4aeada --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/actions/OpenInSceneBuilderAction.java @@ -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); + } + } +} diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java index 5542db991b2a..81627dbb93b0 100644 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java @@ -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()); }