Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prj1 Getting calendars and created plugin #1375

Open
wants to merge 3 commits into
base: prj1_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions biz.ganttproject.impex.google/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'java'
apply plugin: 'idea'

dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
compile project(':..:ganttproject')
mavenDeps group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
mavenDeps group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'
mavenDeps group: 'com.google.apis', name: 'google-api-services-calendar', version: 'v3-rev237-1.22.0'
}

updateMavenDeps.doFirst {
into project.ext.libDir
}

sourceSets {
main {
java {
srcDir 'src'
}
resources {
}
}
}

task copyPlugin(type: Copy) {
into(new File(rootProject.pluginsDir, project.name))
from(jar.outputs.getFiles().getFiles().flatten())
from(fileTree(".")) {
include "plugin.xml"
include "lib/**.jar"
}
doLast {
println "Copying $project.name to $rootProject.pluginsDir"
}
}
52 changes: 52 additions & 0 deletions biz.ganttproject.impex.google/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin
id="biz.ganttproject.impex.google"
name="Google prj"
version="2.8.4"
provider-name="">

<runtime>
<library name="lib/core/google-http-client-1.22.0.jar">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try to run this code? You have no core directory in this plugin. You have no biz.ganttproject.impex.google.jar in the runtime section either.

<export name="*"/>
</library>
<library name="lib/core/google-http-client-jackson2-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-java6-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-jetty-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-api-client-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/jackson-core-2.8.1.jar">
<export name="*"/>
</library>
<library name="lib/core/jetty-6.1.26.jar">
<export name="*"/>
</library>
<library name="lib/core/jetty-util-6.1.26.jar">
<export name="*"/>
</library>
<library name="lib/core/servlet-api-2.5-20081211.jar">
<export name="*"/>
</library>
<library name="lib/core/google-api-services-calendar-v3-rev237-1.22.0.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="biz.ganttproject.core"/>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="net.sourceforge.ganttproject"/>
</requires>

<extension point="net.sourceforge.ganttproject.exporter">
<exporter class="biz.ganttproject.impex.google.ExporterToGoogle"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,82 @@
package biz.ganttproject.impex.google;

import biz.ganttproject.core.option.GPOptionGroup;
import com.google.api.services.calendar.model.CalendarListEntry;
import net.sourceforge.ganttproject.GPLogger;
import net.sourceforge.ganttproject.action.GPAction;
import net.sourceforge.ganttproject.gui.options.OptionPageProviderBase;
import net.sourceforge.ganttproject.export.ExporterBase;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import java.util.logging.Level;

/**
* Builds option page for google authorization
* Exporter to google calendar
*
* @author Leonid Shatunov ([email protected])
*/
public class GoogleExportOptionPageProvider extends OptionPageProviderBase {
public class ExporterToGoogle extends ExporterBase {

private GoogleAuth myAuth = new GoogleAuth();
private List<CalendarListEntry> myCalendars;

public GoogleExportOptionPageProvider() {
super("impex.google");
@Override
public String getFileTypeDescription() {
return language.getText("impex.google.description");
}

@Override
public GPOptionGroup getOptions() {
return null;
}

@Override
public List<GPOptionGroup> getSecondaryOptions() {
return null;
}

@Override
public GPOptionGroup[] getOptionGroups() {
return new GPOptionGroup[0];
public String getFileNamePattern() {
return null;
}

@Override
public boolean hasCustomComponent() {
return true;
public String proposeFileExtension() {
return null;
}

public Component buildPageComponent() {
@Override
public String[] getFileExtensions() {
return new String[0];
}

@Override
public Component getCustomOptionsUI() {
JPanel result = new JPanel(new BorderLayout());
result.setBorder(new EmptyBorder(5, 5, 5, 5));
JButton testConnectionButton = new JButton(new GPAction("googleConnect") {
@Override
public void actionPerformed(ActionEvent e) {
try {
myAuth.someSampleWork(myAuth.getCalendarService(myAuth.authorize()));
myCalendars = myAuth.getAvaliableCalendarList(myAuth.getCalendarService(myAuth.authorize()));
for (CalendarListEntry i : myCalendars) {
System.out.println(i.getSummary());
}
} catch (Exception e1) {
GPLogger.getLogger(GoogleExportOptionPageProvider.class).log(Level.WARNING, "Something went wrong", e1);
GPLogger.getLogger(ExporterToGoogle.class).log(Level.WARNING, "Something went wrong", e1);
}
}
});
result.add(testConnectionButton, BorderLayout.SOUTH);
return result;
}

@Override
protected ExporterJob[] createJobs(File outputFile, List<File> resultFiles) {
return new ExporterJob[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.DateTime;

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.CalendarScopes;
Expand All @@ -33,6 +32,7 @@

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -68,27 +68,15 @@ public Calendar getCalendarService(Credential credential) throws GeneralSecurity
.build();
}

public void someSampleWork(Calendar service) throws IOException {
// List the next 10 events from the primary calendar.
DateTime now = new DateTime(System.currentTimeMillis());
Events events = service.events().list("primary")
.setMaxResults(10)
.setTimeMin(now)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();
if (items.isEmpty()) {
System.out.println("No upcoming events found.");
} else {
System.out.println("Upcoming events");
for (Event event : items) {
DateTime start = event.getStart().getDateTime();
if (start == null) {
start = event.getStart().getDate();
}
System.out.printf("%s (%s)\n", event.getSummary(), start);
}
public List<CalendarListEntry> getAvaliableCalendarList(Calendar service) throws IOException {
List<CalendarListEntry> myCalendars = service.calendarList().list().execute().getItems();
Iterator<CalendarListEntry> iter = myCalendars.iterator();
while (iter.hasNext()) {
String role = iter.next().getAccessRole();
if (!role.equals("owner") || !role.equals("writer"))
iter.remove();
}
return myCalendars;
}

}
2 changes: 1 addition & 1 deletion ganttproject-builder/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':..:ganttproject','..:biz.ganttproject.core','..:biz.ganttproject.impex.ical','..:biz.ganttproject.impex.msproject2','..:org.ganttproject.impex.htmlpdf','..:org.ganttproject.chart.pert','..:ganttproject-tester'
include ':..:ganttproject','..:biz.ganttproject.core','..:biz.ganttproject.impex.ical','..:biz.ganttproject.impex.msproject2','..:org.ganttproject.impex.htmlpdf','..:org.ganttproject.chart.pert','..:ganttproject-tester','..:biz.ganttproject.impex.google'
3 changes: 0 additions & 3 deletions ganttproject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ dependencies {
mavenDeps group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.1'
mavenDeps group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.1'
mavenDeps group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.6.3', transitive: true
mavenDeps group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
mavenDeps group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'
mavenDeps group: 'com.google.apis', name: 'google-api-services-calendar', version: 'v3-rev237-1.22.0'

}

Expand Down
5 changes: 2 additions & 3 deletions ganttproject/data/resources/language/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impex.csv.description = Comma-Separated-Values file
impex.csv.error.parse_date = Failed to parse date <i>{0}</i>. Date is expected to have format <i>{1}</i> (e.g. today is <i>{2}</i>). You can change date format in the settings dialog
impex.csv.importErrorReport = The following problems were detected during import. Please note that some of them may be harmless<ul>{0}</ul><p>This report has been written to the log file. If you send it to GanttProject developers, please attach your CSV file</p>
impex.html.description = HTML report
impex.google.description = Google Export
impex.ics = iCalendar file
impex.image.description = Raster image file
impex.msproject.description = Microsoft Project file
Expand Down Expand Up @@ -374,8 +375,6 @@ optionPage.impex.ftp.description
#optionPage.impex.ftp.description = Configure access to your FTP-server. This data is used to publish your projects to your project to your web-server. If you specify a subdirectory, it must exist on the server.
optionPage.impex.ftp.label = FTP
optionPage.impex.ftp.title = FTP server settings
optionPage.impex.google.label = Google Export
optionPage.impex.google.title = Google Export settings page
optionPage.project.basic.label = Name and description
optionPage.project.basic.title = Basic project settings
optionPage.project.calendar.label = Calendar
Expand Down Expand Up @@ -570,7 +569,7 @@ separatedFields = Columns delimiter
separator = Separator
settings.app = $Settings...
settings.app.description = Show GanttProject settings
settings.app.pageOrder = ui.general,pageGroup.chart,ganttChart,resourceChart,pageGroup.export,impex.ftp,impex.csv,storage.webdav,impex.google
settings.app.pageOrder = ui.general,pageGroup.chart,ganttChart,resourceChart,pageGroup.export,impex.ftp,impex.csv,storage.webdav
settings.project.pageOrder = project.basic,project.calendar,project.roles
shape = Shape
shortDescription = Description
Expand Down
35 changes: 0 additions & 35 deletions ganttproject/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,6 @@
<export name="*"/>
</library>

<library name="lib/core/google-http-client-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-http-client-jackson2-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-java6-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-oauth-client-jetty-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/google-api-client-1.22.0.jar">
<export name="*"/>
</library>
<library name="lib/core/jackson-core-2.8.1.jar">
<export name="*"/>
</library>
<library name="lib/core/jetty-6.1.26.jar">
<export name="*"/>
</library>
<library name="lib/core/jetty-util-6.1.26.jar">
<export name="*"/>
</library>
<library name="lib/core/servlet-api-2.5-20081211.jar">
<export name="*"/>
</library>
<library name="lib/core/google-api-services-calendar-v3-rev237-1.22.0.jar">
<export name="*"/>
</library>

<library name="data/resources/">
<export name="*"/>
</library>
Expand Down Expand Up @@ -154,7 +120,6 @@
<optionpageprovider class="net.sourceforge.ganttproject.gui.options.ResourceChartOptionPageProvider"/>
<optionpageprovider class="net.sourceforge.ganttproject.document.NetworkOptionPageProvider"/>
<optionpageprovider class="net.sourceforge.ganttproject.document.webdav.WebDavOptionPageProvider"/>
<optionpageprovider class="biz.ganttproject.impex.google.GoogleExportOptionPageProvider"/>
</extension>

<extension
Expand Down