Azure Mobile Service activity template refactor

This commit is contained in:
akrakovsky 2015-06-04 11:00:32 -03:00
Родитель fd5eac997e
Коммит ffaeb84f23
15 изменённых файлов: 1131 добавлений и 53 удалений

Просмотреть файл

@ -56,6 +56,7 @@ limitations under the License.
<depends>com.intellij.modules.java</depends>
<depends>com.intellij.modules.lang</depends>
<depends>org.jetbrains.plugins.gradle</depends>
<depends optional="true">org.jetbrains.android</depends>
<extensions defaultExtensionNs="com.intellij">
<fileEditorProvider implementation="com.microsoftopentechnologies.intellij.helpers.storage.BlobExplorerFileEditorProvider"/>
@ -88,6 +89,10 @@ limitations under the License.
serviceImplementation="com.microsoftopentechnologies.intellij.AzureSettings"/>
</extensions>
<extensions defaultExtensionNs="org.jetbrains.android">
<wizardParameterFactory implementation="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter.AzureWizardParameterFactory"/>
</extensions>
<application-components>
<component>
<implementation-class>com.microsoftopentechnologies.intellij.components.MSOpenTechToolsApplication</implementation-class>

Просмотреть файл

@ -22,5 +22,14 @@
<orderEntry type="library" name="org.apache.commons:commons-lang3:3.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="org.apache.httpcomponents:httpclient-cache:4.3.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="com.microsoft.azure:azure-storage:2.0.0" level="project" />
<orderEntry type="module-library" scope="PROVIDED">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/plugins/android/lib/android.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

Просмотреть файл

@ -451,24 +451,27 @@ public class IDEHelperImpl implements IDEHelper {
}
final VirtualFile libs = libsVf;
final String fileName = zipEntry.getName().split("/")[1];
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
InputStream mobileserviceInputStream = zip.getInputStream(zipEntry);
VirtualFile msVF = libs.createChildData(module.getProject(), zipEntry.getName().split("/")[1]);
msVF.setBinaryContent(getArray(mobileserviceInputStream));
} catch (Throwable ex) {
DefaultLoader.getUIHelper().showException("Error trying to configure Azure Mobile Services", ex);
if(libs.findChild(fileName) == null) {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
InputStream mobileserviceInputStream = zip.getInputStream(zipEntry);
VirtualFile msVF = libs.createChildData(module.getProject(), fileName);
msVF.setBinaryContent(getArray(mobileserviceInputStream));
} catch (Throwable ex) {
DefaultLoader.getUIHelper().showException("Error trying to configure Azure Mobile Services", ex);
}
}
}
});
}
}, ModalityState.defaultModalityState());
});
}
}, ModalityState.defaultModalityState());
}
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter.AzureParameterPane">
<grid id="aae73" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="334" height="71"/>
</constraints>
<properties>
<inheritsPopupMenu value="false"/>
<maximumSize width="334" height="71"/>
<minimumSize width="334" height="71"/>
</properties>
<border type="none"/>
<children>
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3e10d" class="javax.swing.JCheckBox" binding="mobileServicesCheckBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<text value="Azure Mobile Services Client"/>
</properties>
</component>
<component id="6e669" class="javax.swing.JButton" binding="mobileServicesConfigureButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="Configure"/>
</properties>
</component>
<component id="2d5b0" class="javax.swing.JCheckBox" binding="notificationHubCheckBox" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<text value="Notification Hub"/>
</properties>
</component>
<component id="e6a2d" class="javax.swing.JButton" binding="notificationHubConfigureButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="Configure"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

Просмотреть файл

@ -0,0 +1,226 @@
/**
* Copyright 2014 Microsoft Open Technologies Inc.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
import com.google.gson.Gson;
import com.intellij.ide.DataManager;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleWithNameAlreadyExists;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.impl.ProjectFileIndexImpl;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.microsoftopentechnologies.tooling.msservices.components.DefaultLoader;
import com.microsoftopentechnologies.tooling.msservices.model.ms.MobileService;
import org.jdom.JDOMException;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
public class AzureParameterPane extends JPanel {
private JCheckBox mobileServicesCheckBox;
private JPanel mainPanel;
private JCheckBox notificationHubCheckBox;
private JButton notificationHubConfigureButton;
private JButton mobileServicesConfigureButton;
private PlainDocument document;
private MobileService selectedMobileService;
private String connectionString;
private String hubName;
private String senderID;
public AzureParameterPane() {
super(new BorderLayout());
this.add(mainPanel, BorderLayout.CENTER);
document = new PlainDocument();
mobileServicesCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
mobileServicesConfigureButton.setEnabled(mobileServicesCheckBox.isSelected());
updateDocument();
}
});
notificationHubCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
notificationHubConfigureButton.setEnabled(notificationHubCheckBox.isSelected());
updateDocument();
}
});
mobileServicesConfigureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DataContext dataContext = DataManager.getInstance().getDataContext(mainPanel);
final Project project = DataKeys.PROJECT.getData(dataContext);
final MobileServiceConfigForm form = new MobileServiceConfigForm(project);
if(selectedMobileService != null) {
form.setSelectedMobileService(selectedMobileService);
}
form.show();
if(form.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
selectedMobileService = form.getSelectedMobileService();
}
updateDocument();
}
});
notificationHubConfigureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
try {
DataContext dataContext = DataManager.getInstance().getDataContext(mainPanel);
Project project = DataKeys.PROJECT.getData(dataContext);
PsiElement psiElement = ProjectView.getInstance(project).getParentOfCurrentSelection();
VirtualFile vf = null;
if(psiElement instanceof PsiDirectory) {
vf = ((PsiDirectory) psiElement).getVirtualFile();
} else {
vf = psiElement.getContainingFile().getVirtualFile();
}
Module module = ProjectFileIndexImpl.SERVICE.getInstance(project).getModuleForFile(vf);
final NotificationHubConfigForm form = new NotificationHubConfigForm(module);
if(connectionString != null) {
form.setConnectionString(connectionString);
}
if(senderID != null) {
form.setSenderID(senderID);
}
if(hubName != null) {
form.setHubName(hubName);
}
form.show();
if(form.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
connectionString = form.getConnectionString();
hubName = form.getHubName();
senderID = form.getSenderID();
}
updateDocument();
} catch (Throwable e) {
DefaultLoader.getUIHelper().showException("Error loading notification hubs configuration", e);
}
}
});
}
public String getValue() {
try {
return document.getText(0, document.getLength());
} catch (BadLocationException ignored) {
return null;
}
}
public void setValue(String newValue) {
try {
document.replace(0, document.getLength(), newValue, null);
} catch (BadLocationException ignored) {}
}
public PlainDocument getDocument() {
return document;
}
private void updateDocument() {
if((mobileServicesCheckBox.isSelected()
&& !notificationHubCheckBox.isSelected()
&& selectedMobileService != null)
|| (!mobileServicesCheckBox.isSelected()
&& notificationHubCheckBox.isSelected()
&& senderID != null
&& connectionString != null
&& hubName != null)
|| (mobileServicesCheckBox.isSelected()
&& notificationHubCheckBox.isSelected()
&& selectedMobileService != null
&& senderID != null
&& connectionString != null
&& hubName != null)) {
Gson gson = new Gson();
AzureParameters azureParameters = new AzureParameters(
mobileServicesCheckBox.isSelected(),
notificationHubCheckBox.isSelected(),
mobileServicesCheckBox.isSelected() ? selectedMobileService.getAppUrl() : null,
mobileServicesCheckBox.isSelected() ? selectedMobileService.getAppKey() : null,
notificationHubCheckBox.isSelected() ? senderID : null,
notificationHubCheckBox.isSelected() ? connectionString : null,
notificationHubCheckBox.isSelected() ? hubName : null);
String stringVal = gson.toJson(azureParameters);
setValue(stringVal);
} else {
setValue("");
}
}
private class AzureParameters {
public AzureParameters(boolean hasMobileService, boolean hasNotificationHub, String appUrl, String appKey, String sender, String connStr, String hub) {
this.hasMobileService = hasMobileService;
this.hasNotificationHub = hasNotificationHub;
this.appUrl = appUrl;
this.appKey = appKey;
this.sender = sender;
this.connStr = connStr;
this.hub = hub;
}
private boolean hasMobileService;
private boolean hasNotificationHub;
private String appUrl;
private String appKey;
private String sender;
private String connStr;
private String hub;
}
}

Просмотреть файл

@ -0,0 +1,68 @@
/**
* Copyright 2014 Microsoft Open Technologies Inc.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
import com.android.tools.idea.templates.Parameter;
import com.android.tools.idea.wizard.ScopedDataBinder;
import com.android.tools.idea.wizard.WizardParameterFactory;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.text.Document;
public class AzureWizardParameterFactory implements WizardParameterFactory {
@Override
public String[] getSupportedTypes() {
return new String[] { "azureCustomParameter" };
}
@Override
public JComponent createComponent(String s, Parameter parameter) {
return new AzureParameterPane();
}
@Override
public ScopedDataBinder.ComponentBinding<String, JComponent> createBinding(JComponent jComponent, Parameter parameter) {
return new ScopedDataBinder.ComponentBinding<String, JComponent>() {
@Nullable
@Override
public String getValue(JComponent component) {
return ((AzureParameterPane) component).getValue();
}
@Override
public void setValue(@Nullable String newValue, JComponent component) {
((AzureParameterPane) component).setValue(newValue);
}
@Nullable
@Override
public Document getDocument(JComponent component) {
return ((AzureParameterPane) component).getDocument();
}
};
}
}

Просмотреть файл

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter.MobileServiceConfigForm">
<grid id="27dc6" binding="rootPanel" layout-manager="FormLayout">
<rowspec value="top:d:grow"/>
<colspec value="fill:max(d;600px):grow"/>
<colspec value="left:4dlu:noGrow"/>
<colspec value="fill:m:grow"/>
<constraints>
<xy x="-3" y="20" width="652" height="305"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="bca14" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bef58" class="javax.swing.JButton" binding="buttonEdit">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="com/microsoftopentechnologies/intellij/icons/settings.png"/>
<text value=""/>
<verticalAlignment value="1"/>
</properties>
</component>
<component id="ab507" class="javax.swing.JButton" binding="buttonAddService">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font/>
<icon value="com/microsoftopentechnologies/intellij/icons/add.png"/>
<text value=""/>
<verticalAlignment value="1"/>
<verticalTextPosition value="0"/>
</properties>
</component>
<vspacer id="aed8d">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
<grid id="91491" layout-manager="FormLayout">
<rowspec value="fill:max(d;200px):grow"/>
<rowspec value="top:3dlu:noGrow"/>
<rowspec value="fill:100px:noGrow"/>
<colspec value="fill:d:grow"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="cbc38">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="454" height="356"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="de58e" class="javax.swing.JTable" binding="mobileServices">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<scrollpane id="47a39">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="400" height="300"/>
</grid>
<forms defaultalign-horz="false" defaultalign-vert="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c1834" class="javax.swing.JTextPane" binding="summaryTextPane">
<constraints/>
<properties>
<editable value="false"/>
<enabled value="true"/>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
<inspectionSuppressions>
<suppress inspection="NoLabelFor"/>
</inspectionSuppressions>
</form>

Просмотреть файл

@ -0,0 +1,314 @@
/**
* Copyright 2014 Microsoft Open Technologies Inc.
*
* 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.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.microsoftopentechnologies.intellij.forms.CreateMobileServiceForm;
import com.microsoftopentechnologies.intellij.forms.ManageSubscriptionForm;
import com.microsoftopentechnologies.intellij.helpers.ReadOnlyCellTableModel;
import com.microsoftopentechnologies.intellij.helpers.UIHelperImpl;
import com.microsoftopentechnologies.tooling.msservices.components.DefaultLoader;
import com.microsoftopentechnologies.tooling.msservices.helpers.azure.AzureCmdException;
import com.microsoftopentechnologies.tooling.msservices.helpers.azure.rest.AzureRestAPIManagerImpl;
import com.microsoftopentechnologies.tooling.msservices.model.ms.MobileService;
import com.microsoftopentechnologies.tooling.msservices.model.ms.Subscription;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
public class MobileServiceConfigForm extends DialogWrapper {
private JPanel rootPanel;
private JTable mobileServices;
private JButton buttonAddService;
private JButton buttonEdit;
private JTextPane summaryTextPane;
private List<MobileService> mobileServiceList;
private Project project;
private MobileService selectedMobileService;
public MobileServiceConfigForm(Project project) {
super(project, true);
setTitle("Select an Azure Mobile Service");
this.project = project;
getOKAction().setEnabled(false);
summaryTextPane.setContentType("text/html");
ReadOnlyCellTableModel tableModel = new ReadOnlyCellTableModel();
mobileServices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel selectionModel = mobileServices.getSelectionModel();
tableModel.addColumn("Name");
tableModel.addColumn("Region");
tableModel.addColumn("Type");
tableModel.addColumn("Subscription");
mobileServices.setModel(tableModel);
selectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
Object sourceObj = listSelectionEvent.getSource();
if (sourceObj instanceof ListSelectionModel
&& !((ListSelectionModel) sourceObj).isSelectionEmpty()
&& listSelectionEvent.getValueIsAdjusting()
&& mobileServiceList.size() > 0) {
selectedMobileService =
mobileServiceList.get(mobileServices.getSelectionModel().getLeadSelectionIndex());
getOKAction().setEnabled(true);
updateSummary();
}
}
});
buttonEdit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
editSubscriptions();
}
});
buttonAddService.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
CreateMobileServiceForm form = new CreateMobileServiceForm();
form.setServiceCreated(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
fillList();
}
});
}
});
form.setModal(true);
UIHelperImpl.packAndCenterJDialog(form);
form.setVisible(true);
}
});
init();
fillList();
}
private void editSubscriptions() {
ManageSubscriptionForm form = new ManageSubscriptionForm(project);
UIHelperImpl.packAndCenterJDialog(form);
form.setVisible(true);
try {
List<Subscription> subscriptionList = AzureRestAPIManagerImpl.getManager().getSubscriptionList();
if (subscriptionList == null || subscriptionList.size() == 0) {
buttonAddService.setEnabled(false);
// clear the mobile services list
final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
messageTableModel.addColumn("Message");
Vector<String> vector = new Vector<String>();
vector.add("Please sign in/import your Azure subscriptions.");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
} else {
fillList();
}
} catch (AzureCmdException e) {
final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
messageTableModel.addColumn("Message");
Vector<String> vector = new Vector<String>();
vector.add("There has been an error while retrieving the configured Azure subscriptions.");
messageTableModel.addRow(vector);
vector = new Vector<String>();
vector.add("Please retry signing in/importing your Azure subscriptions.");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
}
}
private void updateSummary() {
summaryTextPane.setText("<html> <head> </head> <body style=\"font-family: sans serif;\"> <p style=\"margin-top: 0\">"
+ "<b>Summary:</b></p> <ol> "
+ "<li>Added a reference to the Azure Mobile Services library in project <b>"
+ project.getName()
+ "</b>.</li> "
+ "<li>Added a static method to instantiate MobileServiceClient, connecting to <b>"
+ selectedMobileService.getName()
+ "</b>.</li> "
+ "</ol> <p style=\"margin-top: 0\">After clicking Finish, it might take a few seconds to "
+ "complete set up.</p> </body> </html>");
}
private void fillList() {
getOKAction().setEnabled(false);
mobileServiceList = new ArrayList<MobileService>();
mobileServices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
messageTableModel.addColumn("Message");
Vector<String> vector = new Vector<String>();
vector.add("(loading... )");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading mobile services", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
try {
final List<MobileService> currentSubServices = new ArrayList<MobileService>();
final List<Subscription> subscriptionList = AzureRestAPIManagerImpl.getManager().getSubscriptionList();
final HashMap<UUID, String> subscriptionData = new HashMap<UUID, String>();
if (subscriptionList != null && subscriptionList.size() > 0) {
for (Subscription s : subscriptionList) {
subscriptionData.put(s.getId(), s.getName());
currentSubServices.addAll(AzureRestAPIManagerImpl.getManager().getServiceList(s.getId()));
}
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
buttonAddService.setEnabled(true);
ReadOnlyCellTableModel serviceTableModel = new ReadOnlyCellTableModel();
serviceTableModel.addColumn("Name");
serviceTableModel.addColumn("Region");
serviceTableModel.addColumn("Type");
serviceTableModel.addColumn("Subscription");
int rowIndex = 0;
mobileServices.getSelectionModel().clearSelection();
for (MobileService mobileService : currentSubServices) {
Vector<String> row = new Vector<String>();
row.add(mobileService.getName());
row.add(mobileService.getRegion());
row.add("Mobile service");
row.add(subscriptionData.get(mobileService.getSubcriptionId()));
serviceTableModel.addRow(row);
mobileServiceList.add(mobileService);
if (selectedMobileService != null
&& selectedMobileService.getName().equals(mobileService.getName())
&& selectedMobileService.getSubcriptionId().toString().equals(mobileService.getSubcriptionId().toString())) {
mobileServices.getSelectionModel().setLeadSelectionIndex(rowIndex);
}
rowIndex++;
}
if (rowIndex == 0) {
while (messageTableModel.getRowCount() > 0) {
messageTableModel.removeRow(0);
}
Vector<String> vector = new Vector<String>();
vector.add("There are no Azure Mobile Services on the imported subscriptions");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
} else {
mobileServices.setModel(serviceTableModel);
}
}
}, ModalityState.any());
} else {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
buttonAddService.setEnabled(false);
while (messageTableModel.getRowCount() > 0) {
messageTableModel.removeRow(0);
}
Vector<String> vector = new Vector<String>();
vector.add("Please sign in/import your Azure subscriptions.");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
editSubscriptions();
}
}, ModalityState.any());
}
} catch (Throwable ex) {
DefaultLoader.getUIHelper().showException("Error retrieving service list", ex);
mobileServiceList.clear();
while (messageTableModel.getRowCount() > 0) {
messageTableModel.removeRow(0);
}
Vector<String> vector = new Vector<String>();
vector.add("There has been an error while loading the list of Azure Mobile Services");
messageTableModel.addRow(vector);
mobileServices.setModel(messageTableModel);
}
}
});
}
public MobileService getSelectedMobileService() {
return selectedMobileService;
}
public void setSelectedMobileService(MobileService selectedMobileService) {
this.selectedMobileService = selectedMobileService;
}
@Nullable
@Override
protected JComponent createCenterPanel() {
return rootPanel;
}
}

Просмотреть файл

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter.NotificationHubConfigForm">
<grid id="27dc6" binding="rootPanel" layout-manager="FormLayout">
<rowspec value="center:200px:grow"/>
<rowspec value="top:3dlu:noGrow"/>
<rowspec value="fill:100px:grow"/>
<colspec value="fill:500px:grow"/>
<constraints>
<xy x="20" y="136" width="500" height="305"/>
</constraints>
<properties>
<opaque value="false"/>
</properties>
<border type="none"/>
<children>
<grid id="6cc4b" layout-manager="FormLayout">
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="center:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="center:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="right:d:noGrow"/>
<colspec value="fill:4dlu:noGrow"/>
<colspec value="left:p:grow"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5960c" 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"/>
<forms/>
</constraints>
<properties>
<labelFor value="5960f"/>
<text value="Sender ID:"/>
</properties>
</component>
<component id="5960f" class="javax.swing.JTextField" binding="textSenderID">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
</component>
<component id="5960d" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<labelFor value="f2678"/>
<text value="Connection String:"/>
</properties>
</component>
<component id="f2678" class="javax.swing.JTextField" binding="textConnectionString">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
</component>
<component id="5960e" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<labelFor value="804c9"/>
<text value="Hub Name:"/>
</properties>
</component>
<component id="804c9" class="javax.swing.JTextField" binding="textHubName">
<constraints>
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<scrollpane id="c4718">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false" defaultalign-vert="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="96ed6" class="javax.swing.JTextPane" binding="summaryTextPane">
<constraints/>
<properties>
<editable value="false"/>
<enabled value="true"/>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
<inspectionSuppressions>
<suppress inspection="NoLabelFor" id="4f39e"/>
</inspectionSuppressions>
</form>

Просмотреть файл

@ -0,0 +1,175 @@
/**
* Copyright 2014 Microsoft Open Technologies Inc.
*
* 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.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.microsoftopentechnologies.tooling.msservices.components.DefaultLoader;
import com.microsoftopentechnologies.tooling.msservices.helpers.ServiceCodeReferenceHelper;
import com.microsoftopentechnologies.tooling.msservices.helpers.StringHelper;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class NotificationHubConfigForm extends DialogWrapper {
private JPanel rootPanel;
private JTextField textSenderID;
private JTextField textConnectionString;
private JTextField textHubName;
private JTextPane summaryTextPane;
private Module module;
public NotificationHubConfigForm(Module module) {
super(module.getProject(), true);
this.module = module;
setTitle("Notification Hub Connection Configuration");
init();
DocumentListener documentListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent documentEvent) {
updateSummary();
}
@Override
public void removeUpdate(DocumentEvent documentEvent) {
updateSummary();
}
@Override
public void changedUpdate(DocumentEvent documentEvent) {
updateSummary();
}
};
textHubName.getDocument().addDocumentListener(documentListener);
textConnectionString.getDocument().addDocumentListener(documentListener);
textHubName.getDocument().addDocumentListener(documentListener);
summaryTextPane.setContentType("text/html");
}
private void updateSummary() {
summaryTextPane.setText("<html> <head> </head> <body style=\"font-family: sans serif;\"> <p style=\"margin-top: 0\">"
+ "<b>Summary:</b></p> <ol> "
+ "<li>Will add <a href=\"https://go.microsoft.com/fwLink/?LinkID=280126&clcid=0x409\">"
+ "Notification Hub</a> library to project <b>"
+ module.getProject()
+ "</b>.</li> "
+ "<li>Will add a helper class extending NotificationsHandler, using Notification Hub <b>"
+ getHubName()
+ "</b>.</li> "
+ "<li>Will add a static method to handle notifications using NotificationHubsHelper.</li> "
+ "<li>Will configure the Azure Services Activity referencing the mentioned static methods.</li> "
+ "</ol> <p style=\"margin-top: 0\">After clicking Finish, it might take a few seconds to "
+ "complete set up.</p> </body> </html>");
}
@Nullable
@Override
protected ValidationInfo doValidate() {
String senderId = this.textSenderID.getText().trim();
String connectionString = this.textConnectionString.getText().trim();
String hubName = this.textHubName.getText().trim();
if (StringHelper.isNullOrWhiteSpace(senderId)) {
return new ValidationInfo("The Sender ID must not be empty", textSenderID);
} else if (!senderId.matches("^[0-9]+$")) {
return new ValidationInfo("Invalid Sender ID. The Sender Id must contain only numbers.", textSenderID);
}
if (StringHelper.isNullOrWhiteSpace(connectionString)) {
return new ValidationInfo("The Connection String must not be empty.", textConnectionString);
}
if (StringHelper.isNullOrWhiteSpace(hubName)) {
return new ValidationInfo("The Notification Hub Name must not be empty", textHubName);
} else {
if (hubName.length() < 6 || hubName.length() > 50) {
return new ValidationInfo("The Notification Hub Name must be between 6 and 50 characters long", textHubName);
}
if (!hubName.matches("^[A-Za-z][A-Za-z0-9-]+[A-Za-z0-9]$")) {
return new ValidationInfo("Invalid Notification Hub name. The Notification Hub name must start with a letter, contain only letters, numbers, and hyphens, and end with a letter or number", textHubName);
}
}
return super.doValidate();
}
@Override
protected void doOKAction() {
super.doOKAction();
ProgressManager.getInstance().run(new Task.Backgroundable(module.getProject(), "Downloading Notification Hubs library", false) {
@Override
public void run(ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
ServiceCodeReferenceHelper scrh = new ServiceCodeReferenceHelper();
try {
scrh.addNotificationHubsLibs(module);
} catch (Throwable throwable) {
DefaultLoader.getUIHelper().showException("Error downloading Notification Hubs library", throwable);
}
}
});
}
public String getSenderID() {
return textSenderID.getText();
}
public String getConnectionString() {
return textConnectionString.getText();
}
public String getHubName() {
return textHubName.getText();
}
public void setSenderID(String senderID) {
this.textSenderID.setText(senderID);
}
public void setConnectionString(String connectionString) {
this.textConnectionString.setText(connectionString);
}
public void setHubName(String hubName) {
this.textHubName.setText(hubName);
}
@Nullable
@Override
protected JComponent createCenterPanel() {
return rootPanel;
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<#assign parameters = customParameters?eval><?xml version="1.0"?>
<!--
Copyright 2014 Microsoft Open Technologies, Inc.
@ -16,13 +16,13 @@ limitations under the License.
-->
<recipe>
<#if includeMobileServices>
<#if parameters.hasMobileService>
<dependency mavenUrl="com.google.code.gson:gson:2.3" />
<dependency mavenUrl="com.google.guava:guava:18.0" />
<dependency mavenUrl="com.microsoft.azure:azure-mobile-services-android-sdk:2.+@aar" />
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
<dependency mavenUrl="com.google.android.gms:play-services:3.1.+" />
<dependency mavenUrl="com.microsoft.azure:azure-notifications-handler:1.0.1@aar" />

Просмотреть файл

@ -1,9 +1,10 @@
<#assign parameters = customParameters?eval>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<#if includeMobileServices || includeNotificationHub>
<#if parameters.hasMobileService || parameters.hasNotificationHub>
<uses-permission android:name="android.permission.INTERNET"/>
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
@ -27,7 +28,7 @@
</intent-filter>
</#if>
</activity>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
<receiver android:name="com.microsoft.windowsazure.notifications.NotificationsBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />

Просмотреть файл

@ -1,14 +1,14 @@
<resources>
<#assign parameters = customParameters?eval><resources>
<#if !isNewProject>
<string name="title_${activityToLayout(activityClass)}">${escapeXmlString(activityTitle)}</string>
</#if>
<#if includeMobileServices>
<string name="ms_url_${activityToLayout(activityClass)}">$APPURL_${activityClass}</string>
<string name="ms_key_${activityToLayout(activityClass)}">$APPKEY_${activityClass}</string>
<#if parameters.hasMobileService>
<string name="ms_url_${activityToLayout(activityClass)}">${parameters.appUrl}</string>
<string name="ms_key_${activityToLayout(activityClass)}">${parameters.appKey}</string>
</#if>
<#if includeNotificationHub>
<string name="nh_sender_id_${activityToLayout(activityClass)}">$SENDERID_${activityClass}</string>
<string name="nh_conn_str_${activityToLayout(activityClass)}">$CONNSTR_${activityClass}</string>
<string name="nh_name_${activityToLayout(activityClass)}">$HUBNAME_${activityClass}</string>
<#if parameters.hasNotificationHub>
<string name="nh_sender_id_${activityToLayout(activityClass)}">${parameters.sender}</string>
<string name="nh_conn_str_${activityToLayout(activityClass)}">${parameters.connStr}</string>
<string name="nh_name_${activityToLayout(activityClass)}">${parameters.hub}</string>
</#if>
</resources>

Просмотреть файл

@ -1,37 +1,37 @@
//376d91c0-5633-4523-b012-f2d9ecfbe6c7<#if includeMobileServices>^//010fa0c4-5af1-4f81-95c1-720d9fab8d96</#if><#if includeNotificationHub>^//46cca6b7-ff7d-4e05-9ef2-d7eb4798222e</#if>
package ${packageName};
<#assign parameters = customParameters?eval>
import android.app.Activity;
import android.app.AlertDialog;
<#if includeMobileServices || includeNotificationHub>
<#if parameters.hasMobileService || parameters.hasNotificationHub>
import android.content.Context;
</#if>
import android.os.Bundle;
<#if includeMobileServices>
<#if parameters.hasMobileService>
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gson.JsonElement;
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
import com.microsoft.windowsazure.messaging.NotificationHub;
</#if>
<#if includeMobileServices>
<#if parameters.hasMobileService>
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.MobileServiceException;
import com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable;
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
import com.microsoft.windowsazure.notifications.NotificationsHandler;
import com.microsoft.windowsazure.notifications.NotificationsManager;
</#if>
<#if includeMobileServices>
<#if parameters.hasMobileService>
import java.net.MalformedURLException;
</#if>
public class ${activityClass} extends Activity {
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
public static class NotificationHubsHelper extends NotificationsHandler {
@Override
public void onRegistered(Context context, String gcmRegistrationId) {
@ -73,7 +73,7 @@ public class ${activityClass} extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
<#if includeMobileServices>
<#if parameters.hasMobileService>
try {
//Obtain the MobileServiceClient object to query your mobile service
@ -119,7 +119,7 @@ public class ${activityClass} extends Activity {
createAndShowDialog(e, "Error trying to query mobile service table. Invalid URL");
}
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
handleNotifications(this);
</#if>
@ -158,7 +158,7 @@ public class ${activityClass} extends Activity {
builder.setTitle(title);
builder.create().show();
}
<#if includeMobileServices>
<#if parameters.hasMobileService>
/**
* Creates a new MobileServiceClient instance with preconfigured credentials
@ -175,7 +175,7 @@ public class ${activityClass} extends Activity {
return new MobileServiceClient(appUrl, appKey, context);
}
</#if>
<#if includeNotificationHub>
<#if parameters.hasNotificationHub>
/**
* Enable notifications handling using the NotificationHubsHelper class

Просмотреть файл

@ -58,17 +58,10 @@ limitations under the License.
default="com.mycompany.myapp" />
<parameter
id="includeMobileServices"
name="Azure Mobile Services Client"
type="boolean"
default="false">
</parameter>
<parameter
id="includeNotificationHub"
name="Notification Hub"
type="boolean"
default="false">
id="customParameters"
name="Azure Services Configuration"
type="azureCustomParameter"
constraints="nonempty">
</parameter>
<!-- 128x128 thumbnails relative to template.xml -->