~veger/ganttproject/manual-import

« back to all changes in this revision

Viewing changes to biz.ganttproject.impex.msproject2/src/biz/ganttproject/impex/msproject2/ProjectFileExporter.java

  • Committer: Maarten Bezemer
  • Date: 2012-01-22 12:20:00 UTC
  • Revision ID: maarten.bezemer@gmail.com-20120122122000-qwyec45rjx86wi7o
Updated till 2fe683a778c3 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
GanttProject is an opensource project management tool. License: GPL2
 
2
GanttProject is an opensource project management tool. License: GPL3
3
3
Copyright (C) 2010 Dmitry Barashev
4
4
 
5
5
This program is free software; you can redistribute it and/or
6
6
modify it under the terms of the GNU General Public License
7
 
as published by the Free Software Foundation; either version 2
 
7
as published by the Free Software Foundation; either version 3
8
8
of the License, or (at your option) any later version.
9
9
 
10
10
This program is distributed in the hope that it will be useful,
21
21
import java.util.Calendar;
22
22
import java.util.Date;
23
23
import java.util.HashMap;
24
 
import java.util.Iterator;
25
24
import java.util.Map;
26
25
import java.util.Map.Entry;
27
26
 
35
34
import net.sf.mpxj.Priority;
36
35
import net.sf.mpxj.ProjectCalendar;
37
36
import net.sf.mpxj.ProjectCalendarException;
 
37
import net.sf.mpxj.ProjectCalendarHours;
38
38
import net.sf.mpxj.ProjectFile;
39
39
import net.sf.mpxj.RelationType;
40
40
import net.sf.mpxj.Resource;
101
101
    }
102
102
 
103
103
    private void exportWeekends(ProjectCalendar calendar) {
 
104
        ProjectCalendarHours workingDayHours = calendar.getCalendarHours(Day.MONDAY);
104
105
        calendar.setWorkingDay(Day.MONDAY, getCalendar().getWeekDayType(Calendar.MONDAY) == DayType.WORKING);
105
106
        calendar.setWorkingDay(Day.TUESDAY, getCalendar().getWeekDayType(Calendar.TUESDAY) == DayType.WORKING);
106
107
        calendar.setWorkingDay(Day.WEDNESDAY, getCalendar().getWeekDayType(Calendar.WEDNESDAY) == DayType.WORKING);
107
108
        calendar.setWorkingDay(Day.THURSDAY, getCalendar().getWeekDayType(Calendar.THURSDAY) == DayType.WORKING);
108
109
        calendar.setWorkingDay(Day.FRIDAY, getCalendar().getWeekDayType(Calendar.FRIDAY) == DayType.WORKING);
109
110
        calendar.setWorkingDay(Day.SATURDAY, getCalendar().getWeekDayType(Calendar.SATURDAY) == DayType.WORKING);
 
111
        if (calendar.isWorkingDay(Day.SATURDAY)) {
 
112
            copyHours(workingDayHours, calendar.addCalendarHours(Day.SATURDAY));
 
113
        }
110
114
        calendar.setWorkingDay(Day.SUNDAY, getCalendar().getWeekDayType(Calendar.SUNDAY) == DayType.WORKING);
 
115
        if (calendar.isWorkingDay(Day.SUNDAY)) {
 
116
            copyHours(workingDayHours, calendar.addCalendarHours(Day.SUNDAY));
 
117
        }
 
118
    }
 
119
 
 
120
    private void copyHours(ProjectCalendarHours from, ProjectCalendarHours to) {
 
121
        for (DateRange range : from) {
 
122
            to.addRange(range);
 
123
        }
111
124
    }
112
125
 
113
126
    private void exportHolidays(ProjectCalendar calendar) {
134
147
        rootTask.setDuration(convertDuration(getTaskManager().createLength(
135
148
                getTaskManager().getRootTask().getDuration().getTimeUnit(),
136
149
                getTaskManager().getProjectStart(), getTaskManager().getProjectEnd())));
137
 
        rootTask.setDurationFormat(TimeUnit.DAYS);
 
150
        //rootTask.setDurationFormat(TimeUnit.DAYS);
138
151
        rootTask.setTaskMode(TaskMode.AUTO_SCHEDULED);
139
152
 
140
153
        int i = 0;
171
184
        mpxjTask.setStart(convertStartTime(t.getStart().getTime()));
172
185
        mpxjTask.setFinish(convertFinishTime(t.getEnd().getTime()));
173
186
        mpxjTask.setDuration(convertDuration(t.getDuration()));
174
 
        mpxjTask.setDurationFormat(TimeUnit.DAYS);
 
187
        //mpxjTask.setDurationFormat(TimeUnit.DAYS);
175
188
        Duration[] durations = getActualAndRemainingDuration(mpxjTask);
176
189
        mpxjTask.setActualDuration(durations[0]);
177
190
        mpxjTask.setRemainingDuration(durations[1]);
178
191
        mpxjTask.setPriority(convertPriority(t));
179
192
 
180
193
        exportCustomProperties(t.getCustomValues(), customProperty_fieldType, new CustomPropertySetter() {
 
194
            @Override
181
195
            public void set(FieldType ft, Object value) {
182
196
                mpxjTask.set(ft, value);
183
197
            }
205
219
        c.setTime(gpFinishDate);
206
220
        c.add(Calendar.DAY_OF_YEAR, -1);
207
221
        Date finishTime = myOutputProject.getCalendar().getFinishTime(c.getTime());
208
 
 
209
222
        c.set(Calendar.HOUR, finishTime.getHours());
210
223
        c.set(Calendar.MINUTE, finishTime.getMinutes());
211
224
        return c.getTime();
312
325
 
313
326
        exportDaysOff(hr, mpxjResource);
314
327
        exportCustomProperties(hr, customProperty_fieldType, new CustomPropertySetter() {
 
328
            @Override
315
329
            public void set(FieldType ft, Object value) {
316
330
                mpxjResource.set(ft, value);
317
331
            }