diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/AzureCustomWizardParameter/NotificationHubConfigForm.java b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/AzureCustomWizardParameter/NotificationHubConfigForm.java
index aae729f..90903aa 100644
--- a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/AzureCustomWizardParameter/NotificationHubConfigForm.java
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/AzureCustomWizardParameter/NotificationHubConfigForm.java
@@ -14,13 +14,12 @@
* limitations under the License.
*/
-package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
+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;
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.form b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.form
new file mode 100644
index 0000000..4ab2ef1
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.form
@@ -0,0 +1,148 @@
+
+
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.java b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.java
new file mode 100644
index 0000000..5c42c2c
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ConfigForm.java
@@ -0,0 +1,518 @@
+/**
+ * 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.office365CustomWizardParameter;
+
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.ui.ListCellRendererWrapper;
+import com.intellij.ui.components.JBLabel;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+import com.microsoft.directoryservices.Application;
+import com.microsoftopentechnologies.intellij.forms.CreateOffice365ApplicationForm;
+import com.microsoftopentechnologies.intellij.forms.PermissionsEditorForm;
+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.StringHelper;
+import com.microsoftopentechnologies.tooling.msservices.helpers.graph.ServicePermissionEntry;
+import com.microsoftopentechnologies.tooling.msservices.helpers.o365.Office365Manager;
+import com.microsoftopentechnologies.tooling.msservices.helpers.o365.Office365RestAPIManager;
+import com.microsoftopentechnologies.tooling.msservices.model.Office365Permission;
+import com.microsoftopentechnologies.tooling.msservices.model.Office365PermissionList;
+import com.microsoftopentechnologies.tooling.msservices.model.Office365Service;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Vector;
+
+public class Office365ConfigForm extends DialogWrapper {
+
+ private JPanel rootPanel;
+ private JComboBox cmbApps;
+ private JTable tblAppPermissions;
+ private JButton btnAddApp;
+ private JButton btnSignOut;
+ private JEditorPane editorSummary;
+
+ public Office365ConfigForm(Project project, boolean isListServices, boolean isFileServices, boolean isOutlookServices) {
+ super(project, true);
+
+ setTitle("Configure Office365 Services");
+
+ this.tblAppPermissions.setFocusable(false);
+ this.tblAppPermissions.setRowHeight(35);
+ this.tblAppPermissions.setIntercellSpacing(new Dimension(5, 2));
+ this.tblAppPermissions.setDefaultRenderer(Office365PermissionList.class, new AppPermissionsCR(tblAppPermissions));
+ this.tblAppPermissions.setDefaultEditor(Office365PermissionList.class, new AppPermissionsCR(tblAppPermissions));
+
+ this.cmbApps.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Application app = (Application) cmbApps.getSelectedItem();
+ refreshPermissions(app);
+ }
+ });
+
+ btnAddApp.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ CreateOffice365ApplicationForm form = new CreateOffice365ApplicationForm();
+ form.setModal(true);
+ UIHelperImpl.packAndCenterJDialog(form);
+ form.setVisible(true);
+
+ if (form.getDialogResult() == CreateOffice365ApplicationForm.DialogResult.OK) {
+ refreshApps(form.getApplication().getappId());
+ }
+ }
+ });
+
+ btnSignOut.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // clear the authentication token
+ Office365RestAPIManager.getManager().setAuthenticationToken(null);
+
+ // refresh apps to cause the sign in popup to be displayed
+ refreshApps(null);
+ }
+ });
+
+ refreshApps(null);
+
+ updateSummary(project, isOutlookServices, isFileServices, isListServices);
+
+ init();
+ }
+
+ public Application getApplication() {
+ return (Application) cmbApps.getSelectedItem();
+ }
+
+ @Nullable
+ @Override
+ protected JComponent createCenterPanel() {
+ return rootPanel;
+ }
+
+ private void updateSummary(Project project, boolean isOutlookServices, boolean isFileServices, boolean isListServices) {
+ StringBuilder summary = new StringBuilder();
+ summary.append(" " +
+ "Summary:
");
+
+ if (isOutlookServices) {
+ summary.append("- Will add a reference to the Outlook Services library in project ");
+ summary.append(project.getName());
+ summary.append(".
");
+ summary.append("- Will add a static method to instantiate OutlookClient and list messages.
");
+ }
+
+ if (isFileServices) {
+ summary.append("- Will add a reference to the File Services library in project ");
+ summary.append(project.getName());
+ summary.append(".
");
+ summary.append("- Will add a static method to instantiate SharePointClient and list files.
");
+ }
+
+ if (isListServices) {
+ summary.append("- Will add a reference to the SharePoint Lists library in project ");
+ summary.append(project.getName());
+ summary.append(".
");
+ summary.append("- Will add a static method to instantiate SharepointListsClient and enumerate lists.
");
+ }
+
+ summary.append("- Will configure the Office 365 Activity referencing the mentioned static methods.
");
+ summary.append("- You can follow the link to " +
+ "Office 365 SDK for Android to learn more about the referenced libraries.
");
+
+
+ summary.append("
After clicking Finish, it might take a few seconds to " +
+ "complete set up.
");
+
+ editorSummary.setText(summary.toString());
+ }
+
+ private void fillApps(final String selectedAppId) {
+ final Office365ConfigForm office365ConfigForm = this;
+
+ ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ cmbApps.setRenderer(new StringComboBoxItemRenderer());
+ cmbApps.setModel(new DefaultComboBoxModel(new String[]{"(loading...)"}));
+ cmbApps.setEnabled(false);
+
+ ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
+ messageTableModel.addColumn("Message");
+ Vector vector = new Vector();
+ vector.add("(loading... )");
+ messageTableModel.addRow(vector);
+ tblAppPermissions.setModel(messageTableModel);
+ }
+ }, ModalityState.any());
+
+ final Office365Manager manager = Office365RestAPIManager.getManager();
+
+ try {
+ if (!manager.authenticated()) {
+ manager.authenticate();
+
+ // if we still don't have an authentication token then the
+ // user has cancelled out of login; so we cancel out of this
+ // wizard
+ if (manager.getAuthenticationToken() == null) {
+ ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ office365ConfigForm.close(DialogWrapper.CANCEL_EXIT_CODE);
+ }
+ }, ModalityState.any());
+ return;
+ }
+ }
+
+ Futures.addCallback(manager.getApplicationList(), new FutureCallback>() {
+ @Override
+ public void onSuccess(final List applications) {
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ if (applications.size() > 0) {
+ cmbApps.setRenderer(new ListCellRendererWrapper() {
+ @Override
+ public void customize(JList jList, Application application, int i, boolean b, boolean b2) {
+ setText(application.getdisplayName());
+ }
+ });
+
+ cmbApps.setModel(new DefaultComboBoxModel(applications.toArray()));
+ cmbApps.setEnabled(true);
+
+ int selectedIndex = 0;
+ if (!StringHelper.isNullOrWhiteSpace(selectedAppId)) {
+ selectedIndex = Iterables.indexOf(applications, new Predicate() {
+ @Override
+ public boolean apply(Application application) {
+ return application.getappId().equals(selectedAppId);
+ }
+ });
+ }
+ cmbApps.setSelectedIndex(Math.max(0, selectedIndex));
+ } else {
+ cmbApps.setRenderer(new StringComboBoxItemRenderer());
+ cmbApps.setModel(new DefaultComboBoxModel(new String[]{"No apps configured)"}));
+ cmbApps.setEnabled(false);
+
+ ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
+ messageTableModel.addColumn("Message");
+ Vector vector = new Vector();
+ vector.add("There are no applications configured.");
+ messageTableModel.addRow(vector);
+ tblAppPermissions.setModel(messageTableModel);
+ //tblAppPermissions.setEnabled(false);
+ }
+ }
+ }, ModalityState.any());
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ DefaultLoader.getUIHelper().showException("An error occurred while fetching the list of applications.", throwable);
+ }
+ }, ModalityState.any());
+ }
+ });
+ } catch (Throwable throwable) {
+ DefaultLoader.getUIHelper().showException("An error occurred while trying to authenticate with Office 365", throwable);
+ }
+ }
+
+ private void fillPermissions(@NotNull Application app) throws ParseException {
+ // show a status message while we're fetching permissions
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
+ messageTableModel.addColumn("Message");
+ Vector vector = new Vector();
+ vector.add("(loading... )");
+ messageTableModel.addRow(vector);
+ tblAppPermissions.setModel(messageTableModel);
+
+ //tblAppPermissions.setEnabled(false);
+ }
+ }, ModalityState.any());
+
+ Futures.addCallback(Office365RestAPIManager.getManager().getO365PermissionsForApp(app.getobjectId()), new FutureCallback>() {
+ @Override
+ public void onSuccess(final List servicePermissionEntries) {
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ if (servicePermissionEntries.size() > 0) {
+ tblAppPermissions.setModel(new AppPermissionsTM(servicePermissionEntries));
+ tblAppPermissions.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
+ final TableColumn servicesColumn = tblAppPermissions.getColumnModel().getColumn(0);
+ servicesColumn.setMinWidth(100);
+ servicesColumn.setMaxWidth(250);
+ servicesColumn.setPreferredWidth(185);
+ } else {
+ ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
+ messageTableModel.addColumn("Message");
+ Vector vector = new Vector();
+ vector.add("There are no Office 365 application permissions.");
+ messageTableModel.addRow(vector);
+ tblAppPermissions.setModel(messageTableModel);
+ }
+ }
+ }, ModalityState.any());
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ DefaultLoader.getUIHelper().showException("An error occurred while fetching permissions for Office 365 services.", throwable);
+ }
+ });
+ }
+
+ private void refreshApps(final String selectedAppId) {
+ ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+ @Override
+ public void run() {
+ fillApps(selectedAppId);
+ }
+ });
+ }
+
+ private void refreshPermissions(@NotNull final Application app) {
+ ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ fillPermissions(app);
+ } catch (ParseException e) {
+ DefaultLoader.getUIHelper().showException("An error occurred while fetching permissions for Office 365 services.", e);
+ }
+ }
+ });
+ }
+
+ private class StringComboBoxItemRenderer extends ListCellRendererWrapper {
+ @Override
+ public void customize(JList jList, String s, int i, boolean b, boolean b2) {
+ setText(s);
+ }
+ }
+
+
+ private class AppPermissionsTM extends AbstractTableModel {
+ List servicePermissionEntries;
+
+ public AppPermissionsTM(@NotNull List servicePermissionEntries) {
+ this.servicePermissionEntries = servicePermissionEntries;
+ }
+
+ public List getPermissionEntries() {
+ return servicePermissionEntries;
+ }
+
+ @Override
+ public int getRowCount() {
+ return servicePermissionEntries.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 2;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ if (columnIndex == 0) {
+ return servicePermissionEntries.get(rowIndex).getKey();
+ } else if (columnIndex == 1) {
+ return servicePermissionEntries.get(rowIndex).getValue();
+ } else {
+ throw new IndexOutOfBoundsException("columnIndex");
+ }
+ }
+
+ @Override
+ public void setValueAt(Object value, int rowIndex, int columnIndex) {
+ if (columnIndex == 1) {
+ servicePermissionEntries.get(rowIndex).setValue((Office365PermissionList) value);
+ fireTableCellUpdated(rowIndex, columnIndex);
+ }
+ }
+
+ @Override
+ public Class getColumnClass(int columnIndex) {
+ if (columnIndex == 0) {
+ return Office365Service.class;
+ } else if (columnIndex == 1) {
+ return Office365PermissionList.class;
+ } else {
+ throw new IndexOutOfBoundsException("columnIndex");
+ }
+ }
+
+ @Override
+ public String getColumnName(int columnIndex) {
+ if (columnIndex == 0) {
+ return "Service";
+ } else if (columnIndex == 1) {
+ return "Permissions";
+ } else {
+ throw new IndexOutOfBoundsException("columnIndex");
+ }
+ }
+
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ if (columnIndex == 0) {
+ return false;
+ } else if (columnIndex == 1) {
+ return true;
+ }
+
+ throw new IndexOutOfBoundsException("columnIndex");
+ }
+ }
+
+ private class AppPermissionsCR extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
+ private JPanel panel;
+ private Office365Service service;
+ private Office365PermissionList permissionSet;
+ private JLabel permissionsLabel;
+ private JTable tblAppPermissions;
+ private int currentRow, currentCol;
+
+ public AppPermissionsCR(JTable tblAppPermissions) {
+ this.tblAppPermissions = tblAppPermissions;
+ FormLayout formLayout = new FormLayout(
+ "fill:70px:grow, fill:30px",
+ "center:d:noGrow"
+ );
+ panel = new JPanel(formLayout);
+ panel.setFocusable(false);
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ return getTableCellComponent(table, (Office365PermissionList) value, row);
+ }
+
+ @Override
+ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+ currentRow = row;
+ currentCol = column;
+ return getTableCellComponent(table, (Office365PermissionList) value, row);
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return permissionSet;
+ }
+
+ private Component getTableCellComponent(JTable table, Office365PermissionList permissionSet, int row) {
+ this.permissionSet = permissionSet;
+ this.service = (Office365Service) table.getModel().getValueAt(row, 0);
+
+ // build the label text
+ Iterable enabledPermissions = Iterables.filter(this.permissionSet, new Predicate() {
+ @Override
+ public boolean apply(Office365Permission office365Permission) {
+ return office365Permission.isEnabled();
+ }
+ });
+
+ String permissions = Joiner.on(", ").join(Iterables.transform(enabledPermissions, new Function() {
+ @Override
+ public String apply(Office365Permission office365Permission) {
+ return office365Permission.getName();
+ }
+ }));
+
+ if (StringHelper.isNullOrWhiteSpace(permissions)) {
+ permissions = "No permissions assigned";
+ }
+
+ // setting this to true causes the panel to not draw a background;
+ // if we don't do this then the panel draws the default dialog
+ // background color which looks ugly in a light colored theme
+ panel.setOpaque(false);
+
+ // create the label and the button
+ if (permissionsLabel == null) {
+ panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+
+ CellConstraints constraints = new CellConstraints();
+ permissionsLabel = new JBLabel();
+ panel.add(permissionsLabel, constraints.xy(1, 1));
+
+ JButton button = new JButton("...");
+ button.setOpaque(true);
+ panel.add(button, constraints.xy(2, 1));
+
+ button.addActionListener(new ShowPermissionsDialogActionListener());
+ }
+
+ permissionsLabel.setText(permissions);
+ permissionsLabel.setToolTipText(permissions);
+ return panel;
+ }
+
+ class ShowPermissionsDialogActionListener implements ActionListener {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // this is not exactly intuitive but when you click the button on the table cell
+ // this is the method that gets called; so we pop up the permissions form here
+ PermissionsEditorForm permissionsEditorForm = new PermissionsEditorForm(service.getName(), permissionSet);
+ UIHelperImpl.packAndCenterJDialog(permissionsEditorForm);
+ permissionsEditorForm.setVisible(true);
+
+ if (permissionsEditorForm.getDialogResult() == PermissionsEditorForm.DialogResult.OK) {
+ // update our permissions
+ permissionSet = permissionsEditorForm.getPermissions();
+ tblAppPermissions.getModel().setValueAt(permissionSet, currentRow, currentCol);
+ }
+ fireEditingStopped();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.form b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.form
new file mode 100644
index 0000000..af843c9
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.form
@@ -0,0 +1,76 @@
+
+
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.java b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.java
new file mode 100644
index 0000000..5d6b319
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365ParameterPane.java
@@ -0,0 +1,200 @@
+/**
+ * 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.office365CustomWizardParameter;
+
+import com.google.gson.Gson;
+
+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 com.intellij.ide.DataManager;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.DataKeys;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.microsoft.directoryservices.Application;
+
+public class Office365ParameterPane extends JPanel {
+ private JCheckBox outlookServicesCheckBox;
+ private JPanel mainPanel;
+ private JCheckBox sharepointListsCheckBox;
+ private JCheckBox fileServicesCheckBox;
+ private JCheckBox oneNoteCheckBox;
+ private JButton configureOneNoteButton;
+ private JButton configureOffice365Button;
+ private PlainDocument document;
+ private Application selectedApplication;
+ private String selectedClientID;
+
+ public Office365ParameterPane() {
+ super(new BorderLayout());
+
+ add(mainPanel, BorderLayout.CENTER);
+
+ document = new PlainDocument();
+
+
+ oneNoteCheckBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ configureOneNoteButton.setEnabled(oneNoteCheckBox.isSelected());
+
+ updateDocument();
+ }
+
+
+ });
+
+ ActionListener actionListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ configureOffice365Button.setEnabled(
+ outlookServicesCheckBox.isSelected()
+ || sharepointListsCheckBox.isSelected()
+ || fileServicesCheckBox.isSelected()
+ );
+
+ updateDocument();
+ }
+ };
+ outlookServicesCheckBox.addActionListener(actionListener);
+ sharepointListsCheckBox.addActionListener(actionListener);
+ fileServicesCheckBox.addActionListener(actionListener);
+
+
+ configureOffice365Button.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ DataContext dataContext = DataManager.getInstance().getDataContext(mainPanel);
+ final Project project = DataKeys.PROJECT.getData(dataContext);
+
+ Office365ConfigForm form = new Office365ConfigForm(project,
+ sharepointListsCheckBox.isSelected(),
+ fileServicesCheckBox.isSelected(),
+ outlookServicesCheckBox.isSelected());
+
+ form.show();
+
+ if(form.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
+ selectedApplication = form.getApplication();
+ }
+
+ updateDocument();
+ }
+ });
+
+ configureOneNoteButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ DataContext dataContext = DataManager.getInstance().getDataContext(mainPanel);
+ final Project project = DataKeys.PROJECT.getData(dataContext);
+
+ OneNoteConfigForm form = new OneNoteConfigForm(project);
+ form.show();
+
+ if(form.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
+ selectedClientID = form.getClientId();
+ }
+
+ updateDocument();
+ }
+ });
+ }
+
+
+ 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() {
+ boolean isOffice365Selected =
+ sharepointListsCheckBox.isSelected()
+ || fileServicesCheckBox.isSelected()
+ || outlookServicesCheckBox.isSelected();
+
+ if ((isOffice365Selected
+ && oneNoteCheckBox.isSelected()
+ && selectedApplication != null
+ && selectedClientID != null)
+ || (isOffice365Selected
+ && !oneNoteCheckBox.isSelected()
+ && selectedApplication != null)
+ || (!isOffice365Selected
+ && oneNoteCheckBox.isSelected()
+ && selectedClientID != null)) {
+
+ Gson gson = new Gson();
+
+ Office365Parameters office365Parameters = new Office365Parameters(
+ sharepointListsCheckBox.isSelected(),
+ fileServicesCheckBox.isSelected(),
+ outlookServicesCheckBox.isSelected(),
+ oneNoteCheckBox.isSelected(),
+ isOffice365Selected ? selectedApplication.getappId() : null,
+ isOffice365Selected ? selectedApplication.getdisplayName() : null,
+ oneNoteCheckBox.isSelected() ? selectedClientID : null);
+
+ String stringVal = gson.toJson(office365Parameters);
+
+ setValue(stringVal);
+ } else {
+ setValue("");
+ }
+
+ }
+
+ private class Office365Parameters {
+
+ private boolean isSharepointLists;
+ private boolean isFileServices;
+ private boolean isOutlookServices;
+ private boolean isOneNote;
+ private String appId;
+ private String appName;
+ private String clientId;
+
+ public Office365Parameters(boolean sharepointListsCheckBoxSelected, boolean fileServicesCheckBoxSelected, boolean outlookServicesCheckBoxSelected, boolean oneNoteCheckBoxSelected, String appId, String appName, String clientId) {
+
+ this.isSharepointLists = sharepointListsCheckBoxSelected;
+ this.isFileServices = fileServicesCheckBoxSelected;
+ this.isOutlookServices = outlookServicesCheckBoxSelected;
+ this.isOneNote = oneNoteCheckBoxSelected;
+ this.appId = appId;
+ this.appName = appName;
+ this.clientId = clientId;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365WizardParameterFactory.java b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365WizardParameterFactory.java
new file mode 100644
index 0000000..a99d99f
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/Office365WizardParameterFactory.java
@@ -0,0 +1,60 @@
+/**
+ * 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.office365CustomWizardParameter;
+
+import com.android.tools.idea.templates.Parameter;
+import com.android.tools.idea.wizard.ScopedDataBinder;
+import com.android.tools.idea.wizard.WizardParameterFactory;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.text.Document;
+
+public class Office365WizardParameterFactory implements WizardParameterFactory {
+ @Override
+ public String[] getSupportedTypes() {
+ return new String[] { "office365CustomParameter" };
+ }
+
+ @Override
+ public JComponent createComponent(String s, Parameter parameter) {
+ return new Office365ParameterPane();
+ }
+
+ @Override
+ public ScopedDataBinder.ComponentBinding createBinding(JComponent jComponent, Parameter parameter) {
+ return new ScopedDataBinder.ComponentBinding() {
+ @Nullable
+ @Override
+ public String getValue(JComponent component) {
+ return ((Office365ParameterPane) component).getValue();
+ }
+
+ @Override
+ public void setValue(@Nullable String newValue, JComponent component) {
+ ((Office365ParameterPane) component).setValue(newValue);
+ }
+
+ @Nullable
+ @Override
+ public Document getDocument(JComponent component) {
+ return ((Office365ParameterPane) component).getDocument();
+ }
+ };
+
+ }
+}
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.form b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.form
new file mode 100644
index 0000000..b0448a6
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.form
@@ -0,0 +1,30 @@
+
+
diff --git a/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.java b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.java
new file mode 100644
index 0000000..57b58f4
--- /dev/null
+++ b/src/android/com/microsoftopentechnologies/intellij/helpers/activityConfiguration/office365CustomWizardParameter/OneNoteConfigForm.java
@@ -0,0 +1,66 @@
+/**
+ * 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.office365CustomWizardParameter;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.ui.ValidationInfo;
+import com.intellij.ui.wizard.WizardNavigationState;
+import com.intellij.ui.wizard.WizardStep;
+import com.microsoftopentechnologies.intellij.wizards.activityConfiguration.AddServiceWizardModel;
+import com.microsoftopentechnologies.intellij.wizards.activityConfiguration.ServiceType;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OneNoteConfigForm extends DialogWrapper {
+ private JPanel rootPanel;
+ private JTextField clientIdTextField;
+
+ public OneNoteConfigForm(Project project) {
+ super(project, true);
+
+ setTitle("Configure OneNote Service");
+
+ init();
+ }
+
+
+ public String getClientId() {
+ return clientIdTextField.getText();
+ }
+
+ @Nullable
+ @Override
+ protected ValidationInfo doValidate() {
+ return (clientIdTextField.getText().length() == 0) ?
+ new ValidationInfo("Client ID should no be empty", clientIdTextField)
+ : super.doValidate();
+ }
+
+ @Nullable
+ @Override
+ protected JComponent createCenterPanel() {
+ return rootPanel;
+ }
+
+}
diff --git a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/recipe.xml.ftl b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/recipe.xml.ftl
index 4beb69d..55e2403 100644
--- a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/recipe.xml.ftl
+++ b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/recipe.xml.ftl
@@ -1,4 +1,4 @@
-
+<#assign parameters = customParameters?eval>
-<#if includeOutlookServices>
+<#if parameters.isOutlookServices>
#if>
-<#if includeFileServices>
+<#if parameters.isFileServices>
#if>
-<#if includeOutlookServices || includeFileServices || includeOneNoteServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isOneNote>
#if>
-<#if includeListServices>
+<#if parameters.isSharepointLists>
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
#if>
diff --git a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/AndroidManifest.xml.ftl b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/AndroidManifest.xml.ftl
index 44d0835..545d118 100644
--- a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/AndroidManifest.xml.ftl
+++ b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/AndroidManifest.xml.ftl
@@ -1,5 +1,5 @@
-
-<#if includeOutlookServices || includeFileServices || includeListServices>
+<#assign parameters = customParameters?eval>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
#if>
diff --git a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/res/values/strings.xml.ftl b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/res/values/strings.xml.ftl
index 8c10b65..b25d56c 100644
--- a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/res/values/strings.xml.ftl
+++ b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/res/values/strings.xml.ftl
@@ -1,22 +1,22 @@
-
+<#assign parameters = customParameters?eval>
<#if !isNewProject>
${escapeXmlString(activityTitle)}
#if>
-<#if includeOutlookServices || includeFileServices || includeListServices>
- $O365_APP_ID_${activityClass}
- $O365_NAME_${activityClass}
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
+ ${parameters.appId}
+ ${parameters.appName}
#if>
-<#if includeOutlookServices>
+<#if parameters.isOutlookServices>
https://outlook.com/ews/odata/
#if>
-<#if includeFileServices>
+<#if parameters.isFileServices>
https://mytenant.sharepoint.com/_api/v1.0
#if>
-<#if includeListServices>
+<#if parameters.isSharepointLists>
https://mytenant.sharepoint.com/_api/v1.0
/
#if>
-<#if includeOneNoteServices>
- $O365_CLIENTID_${activityClass}
+<#if parameters.isOneNote>
+ ${parameters.clientId}
#if>
\ No newline at end of file
diff --git a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/src/app_package/Office365Activity.java.ftl b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/src/app_package/Office365Activity.java.ftl
index d9ee1cf..861ffad 100644
--- a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/src/app_package/Office365Activity.java.ftl
+++ b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/root/src/app_package/Office365Activity.java.ftl
@@ -1,42 +1,41 @@
-//376d91c0-5633-4523-b012-f2d9ecfbe6c7<#if includeOutlookServices>^//fa684d69-70b3-41ec-83ff-2f8fa77aeeba#if><#if includeFileServices>^//1073bed4-78c3-4b4a-8a4d-ad874a286d86#if><#if includeListServices>^//6695fd94-10cc-4274-b5df-46a3bc63a33d#if><#if includeOneNoteServices>^//657555dc-6167-466a-9536-071307770d46#if>
-package ${packageName};
+<#assign parameters = customParameters?eval>package ${packageName};
import android.app.Activity;
-<#if includeOutlookServices || includeFileServices || includeListServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
import android.content.Context;
#if>
import android.os.Bundle;
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
import android.util.Log;
#if>
-<#if includeOutlookServices || includeFileServices || includeListServices || includeOneNoteServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists || parameters.isOneNote>
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
#if>
-<#if includeOutlookServices || includeFileServices || includeListServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
import com.google.common.util.concurrent.ListenableFuture;
#if>
-<#if includeFileServices>
+<#if parameters.isFileServices>
import com.microsoft.fileservices.Item;
import com.microsoft.fileservices.odata.SharePointClient;
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
import com.microsoft.live.LiveAuthClient;
import com.microsoft.onenote.api.Notebook;
import com.microsoft.onenote.api.odata.OneNoteApiClient;
#if>
-<#if includeOutlookServices>
+<#if parameters.isOutlookServices>
import com.microsoft.outlookservices.Message;
import com.microsoft.outlookservices.odata.OutlookClient;
#if>
-<#if includeOutlookServices || includeFileServices>
+<#if parameters.isOutlookServices || parameters.isFileServices>
import com.microsoft.services.odata.impl.DefaultDependencyResolver;
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
import com.microsoft.services.odata.impl.LiveAuthDependencyResolver;
import com.microsoft.services.odata.interfaces.LogLevel;
#if>
-<#if includeListServices>
+<#if parameters.isSharepointLists>
import com.microsoft.sharepointservices.Credentials;
import com.microsoft.sharepointservices.ListClient;
import com.microsoft.sharepointservices.Query;
@@ -44,19 +43,19 @@ import com.microsoft.sharepointservices.SPList;
import com.microsoft.sharepointservices.http.Request;
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
import java.util.Arrays;
#if>
-<#if includeOutlookServices || includeFileServices || includeListServices || includeOneNoteServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists || parameters.isOneNote>
import java.util.List;
#if>
public class ${activityClass} extends Activity {
-<#if includeOutlookServices || includeFileServices || includeListServices>
+<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
private final String o365AppId = this.getString(R.string.o365_app_id_${activityToLayout(activityClass)});
private final String o365Name = this.getString(R.string.o365_name_${activityToLayout(activityClass)});
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
private final String CLIENT_ID = this.getString(R.string.o365_clientId_${activityToLayout(activityClass)});
final static public String[] SCOPES = {
"wl.signin",
@@ -79,7 +78,7 @@ public class ${activityClass} extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-<#if includeOutlookServices>
+<#if parameters.isOutlookServices>
OutlookClient outlookClient = getOutlookClient(this);
ListenableFuture> inboxFuture = getInboxMessages(outlookClient);
@@ -98,7 +97,7 @@ public class ${activityClass} extends Activity {
}
});
#if>
-<#if includeFileServices>
+<#if parameters.isFileServices>
SharePointClient sharePointClient = getSharePointClient(this);
ListenableFuture> filesFuture = getMyFiles(sharePointClient);
@@ -117,7 +116,7 @@ public class ${activityClass} extends Activity {
}
});
#if>
-<#if includeListServices>
+<#if parameters.isSharepointLists>
ListClient listClient = getListClient(this);
ListenableFuture> listsFuture = getMyLists(listClient);
@@ -137,7 +136,7 @@ public class ${activityClass} extends Activity {
});
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
try {
Futures.addCallback(this.getDependencyResolver().interactiveInitialize(this), new FutureCallback() {
@Override
@@ -167,7 +166,7 @@ public class ${activityClass} extends Activity {
}
#if>
}
-<#if includeOutlookServices>
+<#if parameters.isOutlookServices>
private static OutlookClient getOutlookClient(Context context) {
// TODO: Implement this invoking AAD or another credentials provider
@@ -182,7 +181,7 @@ public class ${activityClass} extends Activity {
return client.getMe().getFolders().getById("Inbox").getMessages().read();
}
#if>
-<#if includeFileServices>
+<#if parameters.isFileServices>
private static SharePointClient getSharePointClient(Context context) {
// TODO: Implement this invoking AAD or another credentials provider
@@ -197,7 +196,7 @@ public class ${activityClass} extends Activity {
return client.getfiles().read();
}
#if>
-<#if includeListServices>
+<#if parameters.isSharepointLists>
private static ListClient getListClient(Context context) {
Credentials credentials = new Credentials() {
@@ -217,7 +216,7 @@ public class ${activityClass} extends Activity {
return client.getLists(new Query());
}
#if>
-<#if includeOneNoteServices>
+<#if parameters.isOneNote>
protected OneNoteApiClient getOneNoteClient() {
if (oneNoteClient == null) {
oneNoteClient = new OneNoteApiClient(ONENOTE_API_ROOT, getDependencyResolver());
diff --git a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/template.xml b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/template.xml
index 21161bc..b4121c6 100644
--- a/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/template.xml
+++ b/src/android/com/microsoftopentechnologies/intellij/templates/MobileServiceTemplate/Office365Activity/template.xml
@@ -58,34 +58,12 @@ limitations under the License.
default="com.mycompany.myapp" />
+ id="customParameters"
+ name="Office 365 Configuration"
+ constraints="nonempty"
+ type="office365CustomParameter">
-
-
-
-
-
-
-
-
-
-