Office 365 custom activity refactor

This commit is contained in:
akrakovsky 2015-06-04 17:30:55 -03:00
Родитель ffaeb84f23
Коммит d9b29982a6
20 изменённых файлов: 1159 добавлений и 89 удалений

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

@ -90,7 +90,8 @@ limitations under the License.
</extensions>
<extensions defaultExtensionNs="org.jetbrains.android">
<wizardParameterFactory implementation="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter.AzureWizardParameterFactory"/>
<wizardParameterFactory implementation="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.azureCustomWizardParameter.AzureWizardParameterFactory"/>
<wizardParameterFactory implementation="com.microsoftopentechnologies.intellij.helpers.activityConfiguration.office365CustomWizardParameter.Office365WizardParameterFactory"/>
</extensions>
<application-components>

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

@ -1,5 +1,5 @@
<?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">
<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>

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

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.azureCustomWizardParameter;
import com.google.gson.Gson;
import com.intellij.ide.DataManager;
@ -22,21 +22,14 @@ 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;
@ -44,7 +37,6 @@ 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 {

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

@ -15,15 +15,11 @@
*/
package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
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.*;

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

@ -1,5 +1,5 @@
<?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">
<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"/>

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

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.AzureCustomWizardParameter;
package com.microsoftopentechnologies.intellij.helpers.activityConfiguration.azureCustomWizardParameter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
@ -23,6 +23,7 @@ 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.intellij.forms.CreateMobileServiceForm;
import com.microsoftopentechnologies.intellij.forms.ManageSubscriptionForm;
import com.microsoftopentechnologies.intellij.helpers.ReadOnlyCellTableModel;
@ -310,5 +311,11 @@ public class MobileServiceConfigForm extends DialogWrapper {
return rootPanel;
}
@Nullable
@Override
protected ValidationInfo doValidate() {
return (mobileServices.getSelectedRows().length == 0)
? new ValidationInfo("Select a Mobile Service", mobileServices)
: super.doValidate();
}
}

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

@ -1,5 +1,5 @@
<?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">
<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"/>

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

@ -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;

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

@ -0,0 +1,148 @@
<?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.office365CustomWizardParameter.Office365ConfigForm">
<grid id="27dc6" binding="rootPanel" layout-manager="FormLayout">
<rowspec value="center:377px:grow"/>
<rowspec value="top:3dlu:noGrow"/>
<rowspec value="fill:177px:noGrow"/>
<colspec value="fill:max(d;4px):noGrow"/>
<colspec value="fill:d:grow"/>
<constraints>
<xy x="20" y="20" width="608" height="759"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="26a6" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<forms defaultalign-vert="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="bca14" layout-manager="FormLayout">
<rowspec value="center:d:noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="fill:d:grow"/>
<constraints>
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ab507" class="javax.swing.JButton" binding="btnAddApp">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false"/>
</constraints>
<properties>
<font/>
<icon value="com/microsoftopentechnologies/intellij/icons/add.png"/>
<text value=""/>
<toolTipText value="Add a new app"/>
<verticalAlignment value="1"/>
<verticalTextPosition value="0"/>
</properties>
</component>
<component id="4d669" class="javax.swing.JButton" binding="btnSignOut">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<icon value="com/microsoftopentechnologies/intellij/icons/logout.png"/>
<text value=""/>
<toolTipText value="Sign out"/>
</properties>
</component>
</children>
</grid>
<grid id="faebd" layout-manager="GridLayoutManager" row-count="1" 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="1" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="72732" 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"/>
</constraints>
<properties>
<text value="Office 365 App"/>
</properties>
</component>
<component id="ce1ee" class="javax.swing.JComboBox" binding="cmbApps">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="48a31" layout-manager="FormLayout">
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:d:grow"/>
<colspec value="fill:d:grow"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="386e5" 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">
<preferred-size width="485" height="16"/>
</grid>
<forms/>
</constraints>
<properties>
<text value="Permissions"/>
</properties>
</component>
<scrollpane id="923ec">
<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="de58e" class="javax.swing.JTable" binding="tblAppPermissions">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
<scrollpane id="37dac">
<constraints>
<grid row="2" column="1" 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="dbbd8" class="javax.swing.JEditorPane" binding="editorSummary">
<constraints/>
<properties>
<contentType value="text/html"/>
<editable value="false"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
<inspectionSuppressions>
<suppress inspection="NoLabelFor"/>
</inspectionSuppressions>
</form>

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

@ -0,0 +1,518 @@
/**
* 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.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("<html> <head> </head> <body style=\"font-family: sans serif;\"> <p style=\"margin-top: 0\">" +
"<b>Summary:</b></p> <ol> ");
if (isOutlookServices) {
summary.append("<li>Will add a reference to the Outlook Services library in project <b>");
summary.append(project.getName());
summary.append("</b>.</li> ");
summary.append("<li>Will add a static method to instantiate OutlookClient and list messages.</li> ");
}
if (isFileServices) {
summary.append("<li>Will add a reference to the File Services library in project <b>");
summary.append(project.getName());
summary.append("</b>.</li> ");
summary.append("<li>Will add a static method to instantiate SharePointClient and list files.</li> ");
}
if (isListServices) {
summary.append("<li>Will add a reference to the SharePoint Lists library in project <b>");
summary.append(project.getName());
summary.append("</b>.</li> ");
summary.append("<li>Will add a static method to instantiate SharepointListsClient and enumerate lists.</li> ");
}
summary.append("<li>Will configure the Office 365 Activity referencing the mentioned static methods.</li> ");
summary.append("<li>You can follow the link to <a href=\"https://github.com/OfficeDev/Office-365-SDK-for-Android\">" +
"Office 365 SDK for Android</a> to learn more about the referenced libraries.</li> ");
summary.append("</ol> <p style=\"margin-top: 0\">After clicking Finish, it might take a few seconds to " +
"complete set up.</p> </body> </html>");
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<String> vector = new Vector<String>();
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<List<Application>>() {
@Override
public void onSuccess(final List<Application> applications) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (applications.size() > 0) {
cmbApps.setRenderer(new ListCellRendererWrapper<Application>() {
@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<Application>() {
@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<String> vector = new Vector<String>();
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<String> vector = new Vector<String>();
vector.add("(loading... )");
messageTableModel.addRow(vector);
tblAppPermissions.setModel(messageTableModel);
//tblAppPermissions.setEnabled(false);
}
}, ModalityState.any());
Futures.addCallback(Office365RestAPIManager.getManager().getO365PermissionsForApp(app.getobjectId()), new FutureCallback<List<ServicePermissionEntry>>() {
@Override
public void onSuccess(final List<ServicePermissionEntry> 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<String> vector = new Vector<String>();
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<String> {
@Override
public void customize(JList jList, String s, int i, boolean b, boolean b2) {
setText(s);
}
}
private class AppPermissionsTM extends AbstractTableModel {
List<ServicePermissionEntry> servicePermissionEntries;
public AppPermissionsTM(@NotNull List<ServicePermissionEntry> servicePermissionEntries) {
this.servicePermissionEntries = servicePermissionEntries;
}
public List<ServicePermissionEntry> 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<Office365Permission> enabledPermissions = Iterables.filter(this.permissionSet, new Predicate<Office365Permission>() {
@Override
public boolean apply(Office365Permission office365Permission) {
return office365Permission.isEnabled();
}
});
String permissions = Joiner.on(", ").join(Iterables.transform(enabledPermissions, new Function<Office365Permission, String>() {
@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();
}
}
}
}

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

@ -0,0 +1,76 @@
<?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.office365CustomWizardParameter.Office365ParameterPane">
<grid id="27dc6" binding="mainPanel" layout-manager="FormLayout">
<rowspec value="center:33px:noGrow"/>
<rowspec value="center:31px:noGrow"/>
<rowspec value="center:31px:noGrow"/>
<rowspec value="top:10dlu:noGrow"/>
<rowspec value="center:31px:noGrow"/>
<colspec value="left:d:grow"/>
<colspec value="fill:10dlu:noGrow"/>
<colspec value="left:104px:grow"/>
<constraints>
<xy x="20" y="20" width="523" height="165"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="1e4b8" class="javax.swing.JCheckBox" binding="outlookServicesCheckBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<text value="Outlook Services (Mail, Contacts and Calendar)"/>
</properties>
</component>
<component id="a2a8c" class="javax.swing.JCheckBox" binding="sharepointListsCheckBox" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<text value="Sharepoint Lists"/>
</properties>
</component>
<component id="2c29f" class="javax.swing.JCheckBox" binding="oneNoteCheckBox" default-binding="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<text value="OneNote "/>
</properties>
</component>
<component id="4bb6d" class="javax.swing.JButton" binding="configureOneNoteButton">
<constraints>
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
<forms defaultalign-vert="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="Configure"/>
</properties>
</component>
<component id="28acc" class="javax.swing.JCheckBox" binding="fileServicesCheckBox">
<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"/>
<forms/>
</constraints>
<properties>
<text value="File Services (OneDrive for Bussiness and Sharepoint Sites)"/>
</properties>
</component>
<component id="402ab" class="javax.swing.JButton" binding="configureOffice365Button">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
<forms defaultalign-vert="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="Configure"/>
</properties>
</component>
</children>
</grid>
</form>

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

@ -0,0 +1,200 @@
/**
* 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.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;
}
}
}

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

@ -0,0 +1,60 @@
/**
* 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.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<String, JComponent> createBinding(JComponent jComponent, Parameter parameter) {
return new ScopedDataBinder.ComponentBinding<String, JComponent>() {
@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();
}
};
}
}

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

@ -0,0 +1,30 @@
<?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.office365CustomWizardParameter.OneNoteConfigForm">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" 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="500" height="32"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3ec2f" 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"/>
</constraints>
<properties>
<labelFor value="5960f"/>
<text value="Client ID"/>
</properties>
</component>
<component id="e7b56" class="javax.swing.JTextField" binding="clientIdTextField">
<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>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>

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

@ -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;
}
}

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

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<#assign parameters = customParameters?eval><?xml version="1.0"?>
<!--
Copyright 2014 Microsoft Open Technologies, Inc.
@ -16,23 +16,23 @@ limitations under the License.
-->
<recipe>
<#if includeOutlookServices>
<#if parameters.isOutlookServices>
<dependency mavenUrl="com.microsoft.services:outlook-services:(,1.0)" />
</#if>
<#if includeFileServices>
<#if parameters.isFileServices>
<dependency mavenUrl="com.microsoft.services:file-services:(,1.0)" />
</#if>
<#if includeOutlookServices || includeFileServices || includeOneNoteServices>
<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isOneNote>
<dependency mavenUrl="com.microsoft.services:odata-engine-android-impl:(,1.0)@aar" />
</#if>
<#if includeListServices>
<#if parameters.isSharepointLists>
<dependency mavenUrl="com.microsoft.services:sharepoint-services:(,1.0)@aar" />
</#if>
<#if includeOneNoteServices>
<#if parameters.isOneNote>
<dependency mavenUrl="com.microsoft.services:onenote-services:(,1.0)" />
<dependency mavenUrl="com.microsoft.services:live-auth:(,1.0)@aar" />
</#if>

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

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<#if includeOutlookServices || includeFileServices || includeListServices>
<#assign parameters = customParameters?eval><?xml version="1.0"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
<uses-permission android:name="android.permission.INTERNET"/>
</#if>

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

@ -1,22 +1,22 @@
<resources>
<#assign parameters = customParameters?eval><resources>
<#if !isNewProject>
<string name="title_${activityToLayout(activityClass)}">${escapeXmlString(activityTitle)}</string>
</#if>
<#if includeOutlookServices || includeFileServices || includeListServices>
<string name="o365_app_id_${activityToLayout(activityClass)}">$O365_APP_ID_${activityClass}</string>
<string name="o365_name_${activityToLayout(activityClass)}">$O365_NAME_${activityClass}</string>
<#if parameters.isOutlookServices || parameters.isFileServices || parameters.isSharepointLists>
<string name="o365_app_id_${activityToLayout(activityClass)}">${parameters.appId}</string>
<string name="o365_name_${activityToLayout(activityClass)}">${parameters.appName}</string>
</#if>
<#if includeOutlookServices>
<#if parameters.isOutlookServices>
<string name="os_url_${activityToLayout(activityClass)}">https://outlook.com/ews/odata/</string>
</#if>
<#if includeFileServices>
<#if parameters.isFileServices>
<string name="fs_url_${activityToLayout(activityClass)}">https://mytenant.sharepoint.com/_api/v1.0</string>
</#if>
<#if includeListServices>
<#if parameters.isSharepointLists>
<string name="ls_server_url_${activityToLayout(activityClass)}">https://mytenant.sharepoint.com/_api/v1.0</string>
<string name="ls_site_relative_url_${activityToLayout(activityClass)}">/</string>
</#if>
<#if includeOneNoteServices>
<string name="o365_clientId_${activityToLayout(activityClass)}">$O365_CLIENTID_${activityClass}</string>
<#if parameters.isOneNote>
<string name="o365_clientId_${activityToLayout(activityClass)}">${parameters.clientId}</string>
</#if>
</resources>

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

@ -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<List<Message>> inboxFuture = getInboxMessages(outlookClient);
@ -98,7 +97,7 @@ public class ${activityClass} extends Activity {
}
});
</#if>
<#if includeFileServices>
<#if parameters.isFileServices>
SharePointClient sharePointClient = getSharePointClient(this);
ListenableFuture<List<Item>> filesFuture = getMyFiles(sharePointClient);
@ -117,7 +116,7 @@ public class ${activityClass} extends Activity {
}
});
</#if>
<#if includeListServices>
<#if parameters.isSharepointLists>
ListClient listClient = getListClient(this);
ListenableFuture<List<SPList>> 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<Boolean>() {
@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());

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

@ -58,34 +58,12 @@ limitations under the License.
default="com.mycompany.myapp" />
<parameter
id="includeOutlookServices"
name="Outlook Services (Mail, Contacts and Calendar)"
type="boolean"
default="false">
id="customParameters"
name="Office 365 Configuration"
constraints="nonempty"
type="office365CustomParameter">
</parameter>
<parameter
id="includeFileServices"
name="File Services (OneDrive for Business and SharePoint Sites)"
type="boolean"
default="false">
</parameter>
<parameter
id="includeListServices"
name="SharePoint Lists"
type="boolean"
default="false">
</parameter>
<parameter
id="includeOneNoteServices"
name="OneNote"
type="boolean"
default="false">
</parameter>
<!-- 128x128 thumbnails relative to template.xml -->
<thumbs>
<!-- default thumbnail is required -->